ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
Harald Hoyer fe20ad
From 7ed8571a3dbfd768488c1db082e0bebb2c88fbcb Mon Sep 17 00:00:00 2001
Harald Hoyer fe20ad
From: George McCollister <george.mccollister@gmail.com>
Harald Hoyer fe20ad
Date: Thu, 1 Aug 2013 12:40:01 -0500
Harald Hoyer fe20ad
Subject: [PATCH] journal: fix hashmap leak in mmap-cache
Harald Hoyer fe20ad
Harald Hoyer fe20ad
hashmap_free() wasn't being called on m->contexts and m->fds resulting
Harald Hoyer fe20ad
in a leak.
Harald Hoyer fe20ad
Harald Hoyer fe20ad
To reproduce do:
Harald Hoyer fe20ad
	while(1) {
Harald Hoyer fe20ad
		sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
Harald Hoyer fe20ad
		sd_journal_close(j);
Harald Hoyer fe20ad
	}
Harald Hoyer fe20ad
Harald Hoyer fe20ad
Memory usage will increase until OOM.
Harald Hoyer fe20ad
---
Harald Hoyer fe20ad
 src/journal/mmap-cache.c | 4 ++++
Harald Hoyer fe20ad
 1 file changed, 4 insertions(+)
Harald Hoyer fe20ad
Harald Hoyer fe20ad
diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c
Harald Hoyer fe20ad
index 767f555..03b57be 100644
Harald Hoyer fe20ad
--- a/src/journal/mmap-cache.c
Harald Hoyer fe20ad
+++ b/src/journal/mmap-cache.c
Harald Hoyer fe20ad
@@ -307,9 +307,13 @@ static void mmap_cache_free(MMapCache *m) {
Harald Hoyer fe20ad
         while ((c = hashmap_first(m->contexts)))
Harald Hoyer fe20ad
                 context_free(c);
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
+        hashmap_free(m->contexts);
Harald Hoyer fe20ad
+
Harald Hoyer fe20ad
         while ((f = hashmap_first(m->fds)))
Harald Hoyer fe20ad
                 fd_free(f);
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
+        hashmap_free(m->fds);
Harald Hoyer fe20ad
+
Harald Hoyer fe20ad
         while (m->unused)
Harald Hoyer fe20ad
                 window_free(m->unused);
Harald Hoyer fe20ad