[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Am I avoiding memory leaks?
- From: <hanksdc about-inc com>
- To: <rpm-list redhat com>
- Subject: Am I avoiding memory leaks?
- Date: Thu, 5 Jul 2001 10:20:22 +0000 (UTC)
Just wanted to pose some of my code to this group. I'm writing a program that's using rpmlib, and I'm pretty familliar with C, but not all that experienced. I just wanted to pose one of my functions to the group to see if you can see any memory leaks that I am missing. It seems when I run the program, anytime I go over this loop, the memory size of the program increases, but it seems to me I'm freeing eveything I allocate. Am I missing something?
Here's my code: It takes a socket as an argument, to which I spew the results of my database query.
int QA_command( int socket ) {
Header h;
rpmdb db;
rpmdbMatchIterator mi = NULL;
char *name, *version, *release;
char send_line[ SEND_LINE_SIZE ];
rpmReadConfigFiles( NULL, NULL );
if( rpmdbOpen( "", &db, O_RDONLY, 0644 ) != 0 ) {
perror( "rpmdbOpen failed" );
send( socket, DB_OPEN_ERR, DB_OPEN_ERR_LEN, 0 );
return ( COMMAND_FAIL );
}
mi = rpmdbInitIterator( db, RPMDBI_PACKAGES, NULL, 0 );
while( h = rpmdbNextIterator( mi ) ) {
if( h != NULL ) {
headerGetEntry( h, RPMTAG_NAME, NULL, (void **) &name, NULL );
headerGetEntry( h, RPMTAG_VERSION, NULL, (void **) &version, NULL );
headerGetEntry( h, RPMTAG_RELEASE, NULL, (void **) &release, NULL );
snprintf(send_line, SEND_LINE_SIZE, "%s-%s-%s\n", name, version, release);
send( socket, send_line, strnlen( send_line, SEND_LINE_SIZE ), 0 );
}
}
headerFree( h );
rpmdbFreeIterator( mi );
rpmdbClose( db );
return ( COMMAND_SUCCESS );
}
It's simple enough, but I can't see where it's leaking.
Thanks for any pointers,
-- Dan
========================================================================
Daniel Hanks - Systems/Database Administrator
About Inc., Web Services Division
1253 N. Research Way, Suite Q-2500. Orem, UT 84097
ph: 801-437-6023 fax: 801-437-6020 email: hanksdc@about-inc.com
========================================================================
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
[]