Bug 98269 - Memory leak in rpmdbNextIterator
Memory leak in rpmdbNextIterator
Status: CLOSED WORKSFORME
Product: Red Hat Linux
Classification: Retired
Component: rpm (Show other bugs)
9
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Jeff Johnson
Mike McLean
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2003-06-29 15:35 EDT by Ian Pilcher
Modified: 2007-04-18 12:55 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2003-07-03 11:22:02 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Ian Pilcher 2003-06-29 15:35:00 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225

Description of problem:
Using rpmdbNextIterator to iterate through all of the RPMs installed on my
system exposes a memory leak.



Here is my test program (rpmtest.c):

#include <stdlib.h>
#include <mcheck.h>
#include <stdio.h>

#include <rpmlib.h>
#include <rpmts.h>
#include <rpmdb.h>

int main(int argc, char *argv[])
{
    rpmts               ts;
    rpmdbMatchIterator    i;

    if (rpmReadConfigFiles(NULL, NULL) != 0)
    {
        fputs("Error reading RPM configuration\n", stderr);
        exit(__LINE__);
    }

    if ((ts = rpmtsCreate()) == NULL)
    {
        fputs("Error creating RPM transaction set\n", stderr);
        exit(__LINE__);
    }

    if ((i = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 0)) == NULL)
    {
        fputs("Error creating RPM database iterator\n", stderr);
        exit(__LINE__);
    }

    rpmdbFreeIterator(i);
    rpmtsFree(ts);

    mtrace();

    if ((ts = rpmtsCreate()) == NULL)
    {
        fputs("Error creating RPM transaction set\n", stderr);
        exit(__LINE__);
    }

    if ((i = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 0)) == NULL)
    {
        fputs("Error creating RPM database iterator\n", stderr);
        exit(__LINE__);
    }

#ifdef DO_LOOP
    while (rpmdbNextIterator(i) != NULL);
#endif

    rpmdbFreeIterator(i);
    rpmtsFree(ts);

    return 0;
}

And here's a session showing the problem:

[pilcher@home temp]$ gcc -g -Wall -I/usr/include/rpm -o rpmtest rpmtest.c -lrpm
[pilcher@home temp]$ MALLOC_TRACE=malloc.log ./rpmtest
[pilcher@home temp]$ mtrace malloc.log
No memory leaks.
[pilcher@home temp]$ gcc -g -Wall -I/usr/include/rpm -DDO_LOOP -o rpmtest
rpmtest.c -lrpm
[pilcher@home temp]$ MALLOC_TRACE=malloc.log ./rpmtest
[pilcher@home temp]$ mtrace malloc.log

Memory not freed:
-----------------
   Address     Size     Caller
0x0805feb8     0x29  at 0x40045fe6
0x0805fee8     0x29  at 0x40045fe6
0x0805ff18     0x29  at 0x40045fe6
0x0805ff48     0x29  at 0x40045fe6
0x0805ff78     0x29  at 0x40045fe6
0x0805ffa8     0x29  at 0x40045fe6
0x0805ffd8     0x29  at 0x40045fe6
0x0806b780     0x29  at 0x40045fe6
0x0806b7b0     0x29  at 0x40045fe6 

Version-Release number of selected component (if applicable):
rpm-4.2-0.69

How reproducible:
Always

Steps to Reproduce:
See above.

Actual Results:  See above.

Expected Results:  No memory leaks.

Additional info:
Comment 1 Jeff Johnson 2003-07-03 11:22:02 EDT
A slightly modified version of your program run with
valgrind indicates

==15763== LEAK SUMMARY:
==15763==    definitely lost: 0 bytes in 0 blocks.
==15763==      possibly lost: 0 bytes in 0 blocks.
==15763==    still reachable: 36710 bytes in 1801 blocks.
==15763==         suppressed: 0 bytes in 0 blocks.

Yes, no leaks with mtrace either.

There was a leak with signature checking, fixed in latest rpm-4.2.1
(and rpm-4.2-1 IIRC).
Comment 2 Ian Pilcher 2003-07-03 17:15:31 EDT
Confirmed that the memory leak is gone in rpm-4.2.1-0.11.

Shouldn't the resolution be RAWHIDE?

Note You need to log in before you can comment on or make changes to this bug.