<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV>Hello Panu,</DIV>
<DIV> </DIV>
<DIV>Thanks for the quick and detailed response, it helped getting rid of several memory leaks.</DIV>
<DIV> </DIV>
<DIV>When I was writing my application I was referring to RPM books that are currently available. </DIV>
<DIV> </DIV>
<DIV>But there is NO good reference book on how to use rpm library using C programming.</DIV>
<DIV> </DIV>
<DIV>Thanks,</DIV>
<DIV> </DIV>
<DIV>SK.<BR><BR>--- On <B>Wed, 5/13/09, Panu Matilainen <I><pmatilai@laiskiainen.org></I></B> wrote:<BR></DIV>
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(16,16,255) 2px solid"><BR>From: Panu Matilainen <pmatilai@laiskiainen.org><BR>Subject: Re: Memoy Leaks in RPM; Version, rpm-4.6.0<BR>To: innovative_c@yahoo.com, "General discussion about the RPM package manager" <rpm-list@lists.rpm.org><BR>Date: Wednesday, May 13, 2009, 6:53 AM<BR><BR>
<DIV class=plainMail>On Mon, 11 May 2009, Creative Innovative wrote:<BR><BR>> Hi Folks,<BR>> <BR>> I am using a C utility that uses RPM to install packages.<BR>> <BR>> RPM Version:: rpm-4.6.0<BR>> <BR>> When I run the C program with Valgrind. I get a bunch of memory leaks.<BR>> <BR>> Can someone let me know,if some of them are know or will it get fixed.<BR><BR>In general, the "still reachable" reports of valgrind aren't that interesting with rpm:<BR>- For many things you need to call shutdown routines to free memory if<BR> you care.<BR>- For many things rpm does deliberate one-shot allocation of "static"<BR> data such as data structures around tag table, that it doesn't bother<BR> freeing on exit.<BR><BR>Reports on other leaks are, of course, most welcome.<BR><BR>> ==13315== 72 bytes in 1 blocks are definitely lost in loss record 19 of<BR>> 54<BR>> ==13315==
at 0x4028122: calloc (vg_replace_malloc.c:397)<BR>> ==13315== by 0x45E1E8F: PR_Calloc (in /lib/libnspr4.so)<BR>> ==13315== by 0x42A1356: (within /lib/libnss3.so)<BR>> ==13315== by 0x42A13A0: (within /lib/libnss3.so)<BR>> ==13315== by 0x42A12B3: (within /lib/libnss3.so)<BR>> ==13315== by 0x4297F7A: (within /lib/libnss3.so)<BR>> ==13315== by 0x429C8C3: (within /lib/libnss3.so)<BR>> ==13315== by 0x425E265: (within /lib/libnss3.so)<BR>> ==13315== by 0x425E563: NSS_NoDB_Init (in /lib/libnss3.so)<BR>> ==13315== by 0x40B7BFE: rpmInitCrypto (in /usr/lib/librpmio-4.6.so)<BR>> ==13315== by 0x40768D9: rpmtsCreate (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x804B3A3: executeTransactionUsingRpm (rpmutform.c:1698)<BR><BR>You need to call
rpmFreeCrypto() to shut down NSS before exit if you want to get rid of this one.<BR><BR>> ==13315== 5 bytes in 1 blocks are still reachable in loss record 1 of 54<BR>> ==13315== at 0x402A06E: malloc (vg_replace_malloc.c:207)<BR>> ==13315== by 0x4074380: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x4074F0D: rpmReadConfigFiles (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x804B341: executeTransactionUsingRpm (rpmutform.c:1682)<BR>> ==13315== by 0x80493DB: main (callRpmUtil.c:16)<BR>> ==13315==<BR>> ==13315==<BR>> ==13315== 6 bytes in 1 blocks are still reachable in loss record 2 of 54<BR>> ==13315== at 0x402A06E: malloc (vg_replace_malloc.c:207)<BR>> ==13315== by 0x40743F3: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x4074F8E: rpmReadConfigFiles (in
/usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x804B341: executeTransactionUsingRpm (rpmutform.c:1682)<BR>> ==13315== by 0x80493DB: main (callRpmUtil.c:16)<BR><BR>Call rpmFreeRpmrc() before exit.<BR><BR>> ==13315==<BR>> ==13315==<BR>> ==13315== 12 bytes in 8 blocks are still reachable in loss record 3 of 54<BR>> ==13315== at 0x402A06E: malloc (vg_replace_malloc.c:207)<BR>> ==13315== by 0x40B06F0: addMacro (in /usr/lib/librpmio-4.6.so)<BR>> ==13315== by 0x40B1E59: (within /usr/lib/librpmio-4.6.so)<BR>> ==13315== by 0x40B1ED8: rpmDefineMacro (in /usr/lib/librpmio-4.6.so)<BR>> ==13315== by 0x40B1FA1: rpmLoadMacroFile (in /usr/lib/librpmio-4.6.so)<BR>> ==13315== by 0x40B21E2: rpmInitMacros (in /usr/lib/librpmio-4.6.so)<BR>> ==13315== by 0x4074F4A: rpmReadConfigFiles
(in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x804B341: executeTransactionUsingRpm (rpmutform.c:1682)<BR>> ==13315== by 0x80493DB: main (callRpmUtil.c:16)<BR><BR>Call rpmFreeMacros() before exit.<BR><BR>> ==13315==<BR>> ==13315== 16 bytes in 2 blocks are still reachable in loss record 4 of 54<BR>> ==13315== at 0x402A06E: malloc (vg_replace_malloc.c:207)<BR>> ==13315== by 0x4072382: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x407257B: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x40744B9: rpmSetTables (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x40747BF: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x4074F5E: rpmReadConfigFiles (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x804B341: executeTransactionUsingRpm (rpmutform.c:1682)<BR>>
==13315== by 0x80493DB: main (callRpmUtil.c:16)<BR><BR>This is again rpmrc stuff, see above.<BR><BR>> ==13315== 22 bytes in 1 blocks are still reachable in loss record 6 of 54<BR>> ==13315== at 0x402A06E: malloc (vg_replace_malloc.c:207)<BR>> ==13315== by 0x407E592: rpmtsAcquireLock (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x407B54B: rpmtsRun (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x804AE32: invokeRpmToRunTrans (rpmutform.c:1475)<BR>> ==13315== by 0x804B73B: executeTransactionUsingRpm (rpmutform.c:1812)<BR>> ==13315== by 0x80493DB: main (callRpmUtil.c:16)<BR><BR>This is deliberate one-shot initialization (and alloc).<BR><BR>> ==13315==<BR>> ==13315==<BR>> ==13315== 24 bytes in 1 blocks are still reachable in loss record 7 of 54<BR>> ==13315== at 0x402A06E: malloc
(vg_replace_malloc.c:207)<BR>> ==13315== by 0x40B6119: (within /usr/lib/librpmio-4.6.so)<BR>> ==13315== by 0x40B62A1: rpmlog (in /usr/lib/librpmio-4.6.so)<BR>> ==13315== by 0x406126C: rpmReadPackageFile (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x8049AC1: addInstallPkgToRpmTs (rpmutform.c:369)<BR>> ==13315== by 0x8049D93: addPkgForInstall (rpmutform.c:463)<BR>> ==13315== by 0x804A10B: processTransList (rpmutform.c:630)<BR>> ==13315== by 0x804B638: executeTransactionUsingRpm (rpmutform.c:1776)<BR>> ==13315== by 0x80493DB: main (callRpmUtil.c:16)<BR><BR>Call rpmlogClose() before exit.<BR><BR>> ==13315== 24 bytes in 1 blocks are still reachable in loss record 9 of 54<BR>> ==13315== at 0x4028122: calloc (vg_replace_malloc.c:397)<BR>> ==13315==
by 0x40B6B76: rpmluaNew (in /usr/lib/librpmio-4.6.so)<BR>> ==13315== by 0x40B72CA: rpmluaGetPrintBuffer (in<BR>> /usr/lib/librpmio-4.6.so)<BR>> ==13315== by 0x4074FA6: rpmReadConfigFiles (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x804B341: executeTransactionUsingRpm (rpmutform.c:1682)<BR>> ==13315== by 0x80493DB: main (callRpmUtil.c:16)<BR><BR>Another one-shot initialization, but rpm >= 4.7.0 the lua subsystem is shutdown too, eliminating this.<BR><BR>> ==13315== 32 bytes in 1 blocks are still reachable in loss record 12 of<BR>> 54<BR>> ==13315== at 0x4028122: calloc (vg_replace_malloc.c:397)<BR>> ==13315== by 0x40593A5: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x405941E: rpmGetFilesystemList (in<BR>> /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x4077B57:
rpmtsInitDSI (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x407B714: rpmtsRun (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x804AE32: invokeRpmToRunTrans (rpmutform.c:1475)<BR>> ==13315== by 0x804B6A8: executeTransactionUsingRpm (rpmutform.c:1793)<BR>> ==13315== by 0x80493DB: main (callRpmUtil.c:16)<BR><BR>Call rpmFreeFileSystems() before exit.<BR><BR>> ==13315== 42 bytes in 1 blocks are still reachable in loss record 14 of<BR>> 54<BR>> ==13315== at 0x402A06E: malloc (vg_replace_malloc.c:207)<BR>> ==13315== by 0x406A8A9: rpmdsNewDNEVR (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x406A9F2: rpmdsNext (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x406ABD1: rpmdsSearch (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x4056184: (within
/usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x405654F: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x40568AA: rpmtsCheck (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x804ACE6: invokeRpmToRunTrans (rpmutform.c:1422)<BR>> ==13315== by 0x804B6A8: executeTransactionUsingRpm (rpmutform.c:1793)<BR>> ==13315== by 0x80493DB: main (callRpmUtil.c:16)<BR>> ==13315==<BR>> ==13315==<BR>> ==13315== 48 bytes in 1 blocks are still reachable in loss record 15 of<BR>> 54<BR>> ==13315== at 0x402A06E: malloc (vg_replace_malloc.c:207)<BR>> ==13315== by 0x406AFE9: rpmdsMerge (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x406B76F: rpmdsRpmlib (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x4056162: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by
0x405654F: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x40568AA: rpmtsCheck (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x804ACE6: invokeRpmToRunTrans (rpmutform.c:1422)<BR>> ==13315== by 0x804B6A8: executeTransactionUsingRpm (rpmutform.c:1793)<BR>> ==13315== by 0x80493DB: main (callRpmUtil.c:16)<BR><BR>This is from rpmlib() dependency set which is another one-shot initialization, freeing it is more fuss than worth.<BR><BR>[...bunch of dupes snipped...]<BR><BR>> ==13315== 1,256 bytes in 2 blocks are still reachable in loss record 43<BR>> of 54<BR>> ==13315== at 0x4028122: calloc (vg_replace_malloc.c:397)<BR>> ==13315== by 0x405239F: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x4052839: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x4052344: rpmTagGetValue (in
/usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x404C51A: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x404DBBE: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x404DEFB: rpmdbOpen (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x40771AF: rpmtsOpenDB (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x407724A: rpmtsInitIterator (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x4077573: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x4077710: rpmtsGetKeyring (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x40610FE: rpmReadPackageFile (in /usr/lib/librpm-4.6.so)<BR>> ==13315==<BR><BR>This is rpm tag table stuff, another "static" item using one-shot allocation.<BR><BR>> <BR>> ==13315== 21,792 bytes in 506 blocks are still reachable in loss record<BR>> 53 of 54<BR>>
==13315== at 0x402A06E: malloc (vg_replace_malloc.c:207)<BR>> ==13315== by 0x402A1EF: realloc (vg_replace_malloc.c:429)<BR>> ==13315== by 0x405F853: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x405B425: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x405AAF1: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x405EFF2: fsmSetup (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x4063872: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x4064B0B: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x4064311: (within /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x407D5A3: rpmtsRun (in /usr/lib/librpm-4.6.so)<BR>> ==13315== by 0x804AE32: invokeRpmToRunTrans (rpmutform.c:1475)<BR>> ==13315== by 0x804B73B:
executeTransactionUsingRpm (rpmutform.c:1812)<BR><BR>Hard to say for sure as there are no debugging symbols for librpm. Could be SELinux related (maybe rpm 4.6.0 isn't shutting down selinux properly, don't remember for sure).<BR><BR>Mind you there certainly are leaks in 4.6.0 (on various rarely used error paths typically), known ones are fixed in 4.7.0 and 4.6.x branch in git already.<BR><BR> - Panu -<BR></DIV></BLOCKQUOTE></td></tr></table><br>