[Rpm-maint] [rpm-software-management/rpm] rpmtsOpenDb leaks memory (Issue #1861)

Ramiro Romero Dapozo notifications at github.com
Tue Dec 14 16:09:51 UTC 2021


The rpmtsOpenDb function  is allocating memory which is not released after running rpmtsCloseDB. This is happening in RPM version 1.17.

I found out about this while adapting a tool that needs to list out all the installed packages using the RPM library.
However, one quick way to produce without an example program is running:
`valgrind rpm -qa` in OpenSUSE Tumbleweed:

```
ramiro at localhost:~> rpm --version
RPM version 4.17.0
ramiro at localhost:~> valgrind  --leak-check=full rpm -qa > /dev/null
==16273== Memcheck, a memory error detector
==16273== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==16273== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==16273== Command: rpm -qa
==16273== 
==16273== 
==16273== HEAP SUMMARY:
==16273==     in use at exit: 1,235 bytes in 33 blocks
==16273==   total heap usage: 143,514 allocs, 143,481 frees, 168,315,320 bytes allocated
==16273== 
==16273== 40 bytes in 1 blocks are definitely lost in loss record 1 of 6
==16273==    at 0x48485EF: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==16273==    by 0x48E6193: rcalloc (rpmmalloc.c:55)
==16273==    by 0x48B2D71: UnknownInlinedFun (dbi.c:40)
==16273==    by 0x48B2D71: ndb_Open.lto_priv.0 (glue.c:119)
==16273==    by 0x487984D: UnknownInlinedFun (dbi.c:166)
==16273==    by 0x487984D: pkgdbOpen (rpmdb.c:145)
==16273==    by 0x487B443: doOpen (rpmdb.c:356)
==16273==    by 0x487D04D: openDatabase.lto_priv.0 (rpmdb.c:524)
==16273==    by 0x489EC40: UnknownInlinedFun (rpmdb.c:555)
==16273==    by 0x489EC40: rpmtsOpenDB (rpmts.c:98)
==16273==    by 0x489F497: rpmtsInitIterator (rpmts.c:198)
==16273==    by 0x488F1B8: UnknownInlinedFun (query.c:521)
==16273==    by 0x488F1B8: rpmcliArgIter (query.c:554)
==16273==    by 0x488F449: rpmcliQuery (query.c:623)
==16273==    by 0x10A9DB: main (rpm.c:279)
==16273== 
==16273== 720 bytes in 18 blocks are definitely lost in loss record 6 of 6
==16273==    at 0x48485EF: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==16273==    by 0x48E6193: rcalloc (rpmmalloc.c:55)
==16273==    by 0x48B2D71: UnknownInlinedFun (dbi.c:40)
==16273==    by 0x48B2D71: ndb_Open.lto_priv.0 (glue.c:119)
==16273==    by 0x487B19B: UnknownInlinedFun (dbi.c:166)
==16273==    by 0x487B19B: indexOpen.lto_priv.0 (rpmdb.c:193)
==16273==    by 0x487B469: doOpen (rpmdb.c:359)
==16273==    by 0x487D04D: openDatabase.lto_priv.0 (rpmdb.c:524)
==16273==    by 0x489EC40: UnknownInlinedFun (rpmdb.c:555)
==16273==    by 0x489EC40: rpmtsOpenDB (rpmts.c:98)
==16273==    by 0x489F497: rpmtsInitIterator (rpmts.c:198)
==16273==    by 0x488F1B8: UnknownInlinedFun (query.c:521)
==16273==    by 0x488F1B8: rpmcliArgIter (query.c:554)
==16273==    by 0x488F449: rpmcliQuery (query.c:623)
==16273==    by 0x10A9DB: main (rpm.c:279)
==16273== 
==16273== LEAK SUMMARY:
==16273==    definitely lost: 760 bytes in 19 blocks
==16273==    indirectly lost: 0 bytes in 0 blocks
==16273==      possibly lost: 0 bytes in 0 blocks
==16273==    still reachable: 475 bytes in 14 blocks
==16273==         suppressed: 0 bytes in 0 blocks
==16273== Reachable blocks (those to which a pointer was found) are not shown.
==16273== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==16273== 
==16273== For lists of detected and suppressed errors, rerun with: -s
==16273== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
```

OpenSUSE version:
```
ramiro at localhost:~> cat /etc/os-release
NAME="openSUSE Tumbleweed"
# VERSION="20211123"
ID="opensuse-tumbleweed"
ID_LIKE="opensuse suse"
VERSION_ID="20211123"
PRETTY_NAME="openSUSE Tumbleweed"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:tumbleweed:20211123"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"
DOCUMENTATION_URL="https://en.opensuse.org/Portal:Tumbleweed"
LOGO="distributor-logo-Tumbleweed"
```



-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1861
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20211214/8c74cf66/attachment.html>


More information about the Rpm-maint mailing list