Skip to content

Commit

Permalink
Moved the free of the malloced memory to a common code path
Browse files Browse the repository at this point in the history
from cppcheck:
[libs/libmythbase/system-unix.cpp:813]: (error) Memory leak: command

This memory still may appear leaked in the child code path (after the fork)
but the execv() call replaces everything in the memory footprint of the
process anyways.  The system will take care of that.

If this doesn't silence cppcheck, we'll need to figure out how to make it
happy, but this code shouldn't actually be leaking anything at this point.
  • Loading branch information
Beirdo committed Jun 30, 2011
1 parent 095022b commit 5b7303b
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions mythtv/libs/libmythbase/system-unix.cpp
Expand Up @@ -683,20 +683,6 @@ void MythSystemUnix::Fork(time_t timeout)
m_stdpipe[0] = p_stdin[1];
m_stdpipe[1] = p_stdout[0];
m_stdpipe[2] = p_stderr[0];

// clean up the memory use
if( command )
free((void *)command);

if( directory )
free((void *)directory);

if( cmdargs )
{
for (i = 0; cmdargs[i]; i++)
free( cmdargs[i] );
free( cmdargs );
}
}
else if (child == 0)
{
Expand Down Expand Up @@ -801,6 +787,21 @@ void MythSystemUnix::Fork(time_t timeout)
}

/* Parent */

// clean up the memory use
if( command )
free((void *)command);

if( directory )
free((void *)directory);

if( cmdargs )
{
for (i = 0; cmdargs[i]; i++)
free( cmdargs[i] );
free( cmdargs );
}

if( GetStatus() != GENERIC_EXIT_RUNNING )
{
CLOSE(p_stdin[0]);
Expand Down

0 comments on commit 5b7303b

Please sign in to comment.