Bug 1018527 - memory leak in libxdg-basedir 1.2.0 (xdgFreeData() does not free cache->runtimeDirectory)
memory leak in libxdg-basedir 1.2.0 (xdgFreeData() does not free cache->runti...
Status: CLOSED ERRATA
Product: Fedora
Classification: Fedora
Component: libxdg-basedir (Show other bugs)
19
x86_64 Linux
unspecified Severity medium
: ---
: ---
Assigned To: Gwyn Ciesla
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2013-10-12 19:35 EDT by andreas
Modified: 2013-11-10 02:10 EST (History)
1 user (show)

See Also:
Fixed In Version: libxdg-basedir-1.2.0-5.fc20
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2013-11-08 22:35:36 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Small patch that frees cache->runtimeDirectory in xdgFreeData() (484 bytes, patch)
2013-10-12 19:35 EDT, andreas
no flags Details | Diff

  None (edit)
Description andreas 2013-10-12 19:35:00 EDT
Created attachment 811661 [details]
Small patch that frees cache->runtimeDirectory in xdgFreeData()

Description of problem:

libxdg-basedir has an internal state allocated by xdgInitHandle() and deallocated by calling xdgWipeHandle(). xdgWipeHandle() calls xdgFreeData(), which is supposed to free all memory allocated to the handle.

Unfortunately, it does not free the string cache->runtimeDirectory, leading to a memory leak of the length of $XDG_RUNTIME_DIR bytes.

This bug seems to have been introduced in upstream commit 648873a319772abf08891f1031e8faaf4b1f2b4c "Added support for Basedir 0.7's XDG_RUNTIME_DIRECTORY." (included in libxdg-basedir 1.2.0):

http://repo.or.cz/w/libxdg-basedir.git/blobdiff/ea242ddf49d385440f9d0bd42fe2c8e9d5841a91..648873a319772abf08891f1031e8faaf4b1f2b4c:/src/basedir.c

Unfortunately, the upstream project at http://n.ethz.ch/student/nevillm/download/libxdg-basedir just throws an HTTP 404 error.

I have attached a simple patch as "basedir.c.patch" that frees cache->runtimeDirectory() in xdgFreeData() in the same way as it frees the other internal data structures. I have compiled and tested it, and it seems to work for me.


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

libxdg-basedir-1.2.0-3.fc19


How reproducible:

Every time. The cleanup function xdgFreeData() does not properly free cache->runtimeDirectory, which is always allocated in xdgUpdateHomeDirectories(), called by xdgUpdateData(), in turn called by xdgInitHandle().


Steps to Reproduce:

1. Compile the test program listed under "additional info" by "gcc -o foo foo.c -l xdg-basedir"
2. Run program through valgrind
3. Observe memory leak


Actual results:

xdgFreeData() does not free cache->runtimeDirectory. valgrind catches this error:

[snip]
==777== 15 bytes in 1 blocks are definitely lost in loss record 11 of 15
==777==    at 0x4C28409: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==777==    by 0x5BF4429: strdup (in /usr/lib64/libc-2.17.so)
==777==    by 0x504176D: xdgUpdateData (in /usr/lib64/libxdg-basedir.so.1.2.0)
==777==    by 0x50419C4: xdgInitHandle (in /usr/lib64/libxdg-basedir.so.1.2.0)
[snap]


Expected results:

xdgFreeData() should free cache->runtimeDirectory.


Additional info:

Here's a small test program that triggers this bug:

#include <basedir.h>

int main()
{
        xdgHandle xdg_handle;

        xdgInitHandle(&xdg_handle);
        xdgWipeHandle(&xdg_handle);

        return 0;
}
Comment 1 Gwyn Ciesla 2013-10-31 09:31:44 EDT
Thanks for the patch, it looks good to me, I'll get updates out ASAP.

Sorry for the delay, I've been swamped.
Comment 2 Fedora Update System 2013-10-31 09:56:05 EDT
libxdg-basedir-1.2.0-5.fc19 has been submitted as an update for Fedora 19.
https://admin.fedoraproject.org/updates/libxdg-basedir-1.2.0-5.fc19
Comment 3 Fedora Update System 2013-10-31 09:56:14 EDT
libxdg-basedir-1.2.0-5.fc18 has been submitted as an update for Fedora 18.
https://admin.fedoraproject.org/updates/libxdg-basedir-1.2.0-5.fc18
Comment 4 Fedora Update System 2013-10-31 09:56:23 EDT
libxdg-basedir-1.2.0-5.fc20 has been submitted as an update for Fedora 20.
https://admin.fedoraproject.org/updates/libxdg-basedir-1.2.0-5.fc20
Comment 5 Fedora Update System 2013-10-31 13:39:39 EDT
Package libxdg-basedir-1.2.0-5.fc20:
* should fix your issue,
* was pushed to the Fedora 20 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing libxdg-basedir-1.2.0-5.fc20'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2013-20390/libxdg-basedir-1.2.0-5.fc20
then log in and leave karma (feedback).
Comment 6 andreas 2013-10-31 17:38:05 EDT
Thanks! I built a sample application in fedora 20 with this fix, ran it through valgrind and it seems to solve the issue.
Comment 7 Fedora Update System 2013-11-08 22:35:36 EST
libxdg-basedir-1.2.0-5.fc19 has been pushed to the Fedora 19 stable repository.  If problems still persist, please make note of it in this bug report.
Comment 8 Fedora Update System 2013-11-08 22:37:59 EST
libxdg-basedir-1.2.0-5.fc18 has been pushed to the Fedora 18 stable repository.  If problems still persist, please make note of it in this bug report.
Comment 9 Fedora Update System 2013-11-10 02:10:31 EST
libxdg-basedir-1.2.0-5.fc20 has been pushed to the Fedora 20 stable repository.  If problems still persist, please make note of it in this bug report.

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