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; }
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. https://admin.fedoraproject.org/updates/libxdg-basedir-1.2.0-5.fc19
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
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
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).
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.