From 7d9c1117e7e42b4de7ccdc7266cce2b0ed51fd7a Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Sun, 1 Dec 2013 21:16:06 +0800 Subject: [PATCH 3/3] Fix memory leak for kqueue: free memory before assign The second memory block leak is that dirs[i] should be freed before assigned a block of memory. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=69332 --- bus/dir-watch-kqueue.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bus/dir-watch-kqueue.c b/bus/dir-watch-kqueue.c index cd55a0a..c9474ea 100644 --- a/bus/dir-watch-kqueue.c +++ b/bus/dir-watch-kqueue.c @@ -272,6 +272,7 @@ bus_set_watched_dirs (BusContext *context, DBusList **directories) else { new_fds[i] = -1; + dbus_free (new_dirs[i]); new_dirs[i] = NULL; continue; } @@ -304,10 +305,16 @@ bus_set_watched_dirs (BusContext *context, DBusList **directories) for (i = 0; i < MAX_DIRS_TO_WATCH; i++) { + _dbus_close (fds[i], NULL); fds[i] = new_fds[i]; + dbus_free (dirs[i]); dirs[i] = new_dirs[i]; } out: - ; + for (i = 0; i < MAX_DIRS_TO_WATCH; i++) + { + _dbus_close (new_fds[i], NULL); + dbus_free (new_dirs[i]); + } } -- 1.7.9.5