Red Hat Bugzilla – Bug 1018527
memory leak in libxdg-basedir 1.2.0 (xdgFreeData() does not free cache->runtimeDirectory)
Last modified: 2013-11-10 02:10:31 EST
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):
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):
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
xdgFreeData() does not free cache->runtimeDirectory. valgrind catches this error:
==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)
xdgFreeData() should free cache->runtimeDirectory.
Here's a small test program that triggers this bug:
Thanks for the patch, it looks good to me, I'll get updates out ASAP.
Sorry for the delay, I've been swamped.
libxdg-basedir-1.2.0-5.fc19 has been submitted as an update for Fedora 19.
libxdg-basedir-1.2.0-5.fc18 has been submitted as an update for Fedora 18.
libxdg-basedir-1.2.0-5.fc20 has been submitted as an update for Fedora 20.
* 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:
then log in and leave karma (feedback).
Thanks! I built a sample application in fedora 20 with this fix, ran it through valgrind and it seems to solve the issue.
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.
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.
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.