ranvi 0 Newbie Poster

Hi All,

I need your help regarding valgrind issues. I have pasted a snippet of code, (not compilable version) which gives the idea of what I am doing. Basically, I have a parent and child process. Child process is running infinite loop (server). Parent process at the end, kills the child. But I am getting valgrind error as possible memory leak. I am not able to figure out the cause. Though valgrind complains the problem is coming from the Msg class, it is not so. Can anyone advice me what could be the cause.

server()
{
   socket();
   bind();
   listen();

   Msg msg;
   while(1)
   {
 	if(msg.transmit() > 0)
             msg.receive();
   }
}

void handler(int sig)
{	
    exit(0);
}

pid_t start()
{
    if  ((childpid = fork()) < 0)
    {
	exit(0);
    }

    if (child_pid == 0)
    {
	signal(SIGTERM, handler);
	server();
	exit(0);
    }
    else
    { 
	return child_pid;
    }

}


void main()
{
    pid_t pid = start();
     //other function calls
    kill(pid, SIGTERM);
}

==1353== 44 bytes in 1 blocks are possibly lost in loss record 34 of 54
==1353== at 0x40068AD: operator new(unsigned int) (vg_replace_malloc.c:224)
==1353== by 0x7E15B75: std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char> const&) (in /usr/lib/libstdc++.so.6.0.12)
==1353== by 0x7E17E4F: std::string::_M_mutate(unsigned int, unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.12)
==1353== by 0x7E17FE9: std::string::_M_replace_safe(unsigned int, unsigned int, char const*, unsigned int) (in /usr/lib/libstdc++.so.6.0.12)
==1353== by 0x7E180AD: std::string::assign(char const*, unsigned int) (in /usr/lib/libstdc++.so.6.0.12)
==1353== by 0x7E18254: std::string::operator=(char const*) (in /usr/lib/libstdc++.so.6.0.12)
==1353== by 0x808C165: Msg::receive(int) (Msg.cc:284)


Sorry, I cannot paste the entire code as it is huge. Hope this gives the picture.

Thanks,
Ranvi

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.