Rayven |
11-02-2006 10:14 AM |
I am attempting to respond to multiple questions at once, so this is a rather long post! :study:
Quote:
Originally Posted by jlliagre
I read elsewhere you were developing on both Red-Hat and Solaris.
If you are compiling on SPARC hardware, I would suggest you to use an alternative method to find out memory leaks on the Solaris side by using Sun Studio 11 compiler and dbx RTC.
|
I am using Sun Studio 10 on the Solaris side, however, I have not ran the code through studio10 to determine memory leaks on Solaris, since this application will be primarily ran on RHEL4.
Quote:
Originally Posted by lorebett
sometimes valgrind reports memory leaks on library functions because some library functions do not actually free memory but keep them in a pool. This might be the case?
|
This may be the case why my application is increasing very quickly. Is there a 'C' function call to force RHEL to free the memory from the pool? The reason I believe this may be a problem, is that when I stop the application and continue to watch the memory, it very slowly drops about 50MB or so, and then holds at that value.
Quote:
Originally Posted by tuxdev
closedir() is better, just doing free() may leak a file handle. Also, never, ever free FILE* and DIR* directly because those are managed by the system.
For the OP issue, what happens in valgrind if you have a trivial program that simply opens and closes a directory?
|
I ran a quick test using opendir/closedir (please excuse any syntax/sematic errors in the code below, I typed this in from memory, and I have a bad memory!)
Code:
int main( int argc, char*argv[])
{
DIR *dp;
struct dirent *dirp;
dp = opendir( argv[1] );
while( (dirp = readdir( dp )) != NULL )
{
fprintf( stderr, "File %s\n", dirp->d_name );
}
closedir( dp );
exit( 0 );
}
Valgrind did not report any memory issues with the test code, even when I wrapped the opendir/closedir code in a for statement. I am wondering if the memory leak is occuring when the child process does not "finish" before the closedir( ) is called. The child processes are not using anything dealing with DIR or dirent pointers. The filenames are copied prior to fork being called.
Code:
if( (dp = opendir( inputDir )) == NULL ) <========Valgrind reports error on this line
{
logError( "Could not open directory path." );
return -1;
}
while( (dirp = readdir( dp )) != NULL )
{
if( (strcmp( dirp->d_name, "." ) != 0) &&
(strcmp( dirp->d_name, ".." ) != 0)
{
// check if valid file using dirp->d_name
// Copy dirp using snprintf adding the path and new prefix
// fork child process to handle the file contents
// Child process does not interact with the parent process at all
// Parent process moves to the next file in the list
}
}
if( closedir( dp ) < 0 )
{
logError( "Error closing file" );
}
return numProcessed;
I do not have direct access to the code right now. It is not on this machine, and the printer is down. If needed, I will try and get more code.
|