Bug 1018527

Summary: memory leak in libxdg-basedir 1.2.0 (xdgFreeData() does not free cache->runtimeDirectory)
Product: [Fedora] Fedora Reporter: andreas
Component: libxdg-basedirAssignee: Gwyn Ciesla <gwync>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 19CC: gwync
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
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-09 03:35:36 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Small patch that frees cache->runtimeDirectory in xdgFreeData() none

Description andreas 2013-10-12 23:35:00 UTC
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 13:31:44 UTC
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 13:56:05 UTC
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 13:56:14 UTC
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 13:56:23 UTC
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 17:39:39 UTC
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 21:38:05 UTC
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-09 03:35:36 UTC
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-09 03:37:59 UTC
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 07:10:31 UTC
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.