From 3a87c6e2f4f18b3833a9fe16c9231f6a9cf4c42c Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Wed, 26 Aug 2015 14:28:27 +0200 Subject: [PATCH] journald: Backport various leak fixes from later journald versions Journald being the typical GNOME application is leaking memory left and right. Let's backport some of the patches that were done in later versions. Fixes: SYS#1843 --- ...emory-leak-in-stdout-journal-streams.patch | 23 ++++++ ...urnal-fix-hashmap-leak-in-mmap-cache.patch | 37 ++++++++++ .../0001-journal-fix-minor-memory-leak.patch | 25 +++++++ ...urnald-accept-EPOLLERR-from-dev-kmsg.patch | 70 +++++++++++++++++++ .../0001-journald-fix-minor-memory-leak.patch | 23 ++++++ .../systemd/systemd_sysmocom-206.inc | 5 ++ 6 files changed, 183 insertions(+) create mode 100644 recipes-fixes/systemd/systemd/0001-Fix-memory-leak-in-stdout-journal-streams.patch create mode 100644 recipes-fixes/systemd/systemd/0001-journal-fix-hashmap-leak-in-mmap-cache.patch create mode 100644 recipes-fixes/systemd/systemd/0001-journal-fix-minor-memory-leak.patch create mode 100644 recipes-fixes/systemd/systemd/0001-journald-accept-EPOLLERR-from-dev-kmsg.patch create mode 100644 recipes-fixes/systemd/systemd/0001-journald-fix-minor-memory-leak.patch diff --git a/recipes-fixes/systemd/systemd/0001-Fix-memory-leak-in-stdout-journal-streams.patch b/recipes-fixes/systemd/systemd/0001-Fix-memory-leak-in-stdout-journal-streams.patch new file mode 100644 index 0000000..5271de7 --- /dev/null +++ b/recipes-fixes/systemd/systemd/0001-Fix-memory-leak-in-stdout-journal-streams.patch @@ -0,0 +1,23 @@ +From f92ae4968f070ef0ada61ba7cd585794fac404dd Mon Sep 17 00:00:00 2001 +From: Dan McGee +Date: Sun, 8 Dec 2013 14:33:45 -0600 +Subject: [PATCH] Fix memory leak in stdout journal streams + +Just as 'identifier' is strdup-ed and freed, we need to do the same for +unit_id. +--- + src/journal/journald-stream.c | 1 + + 1 file changed, 1 insertion(+) + +Index: systemd-206/src/journal/journald-stream.c +=================================================================== +--- systemd-206.orig/src/journal/journald-stream.c ++++ systemd-206/src/journal/journald-stream.c +@@ -339,6 +339,7 @@ void stdout_stream_free(StdoutStream *s) + #endif + + free(s->identifier); ++ free(s->unit_id); + free(s); + } + diff --git a/recipes-fixes/systemd/systemd/0001-journal-fix-hashmap-leak-in-mmap-cache.patch b/recipes-fixes/systemd/systemd/0001-journal-fix-hashmap-leak-in-mmap-cache.patch new file mode 100644 index 0000000..d3984e8 --- /dev/null +++ b/recipes-fixes/systemd/systemd/0001-journal-fix-hashmap-leak-in-mmap-cache.patch @@ -0,0 +1,37 @@ +From 8e6d9397b550f5617fc9231e3a275348cda23c89 Mon Sep 17 00:00:00 2001 +From: George McCollister +Date: Thu, 1 Aug 2013 12:40:01 -0500 +Subject: [PATCH] journal: fix hashmap leak in mmap-cache + +hashmap_free() wasn't being called on m->contexts and m->fds resulting +in a leak. + +To reproduce do: + while(1) { + sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); + sd_journal_close(j); + } + +Memory usage will increase until OOM. +--- + src/journal/mmap-cache.c | 4 ++++ + 1 file changed, 4 insertions(+) + +Index: systemd-206/src/journal/mmap-cache.c +=================================================================== +--- systemd-206.orig/src/journal/mmap-cache.c ++++ systemd-206/src/journal/mmap-cache.c +@@ -307,9 +307,13 @@ static void mmap_cache_free(MMapCache *m + while ((c = hashmap_first(m->contexts))) + context_free(c); + ++ hashmap_free(m->contexts); ++ + while ((f = hashmap_first(m->fds))) + fd_free(f); + ++ hashmap_free(m->fds); ++ + while (m->unused) + window_free(m->unused); + diff --git a/recipes-fixes/systemd/systemd/0001-journal-fix-minor-memory-leak.patch b/recipes-fixes/systemd/systemd/0001-journal-fix-minor-memory-leak.patch new file mode 100644 index 0000000..66b4974 --- /dev/null +++ b/recipes-fixes/systemd/systemd/0001-journal-fix-minor-memory-leak.patch @@ -0,0 +1,25 @@ +From baabc09191178a1d1a7454cd1b601a98dcb22976 Mon Sep 17 00:00:00 2001 +From: Lennart Poettering +Date: Fri, 8 Nov 2013 13:53:25 +0100 +Subject: [PATCH] journal: fix minor memory leak + +--- + src/journal/sd-journal.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c +index 3ccb14a..4579e9e 100644 +--- a/src/journal/sd-journal.c ++++ b/src/journal/sd-journal.c +@@ -1276,7 +1276,7 @@ static void check_network(sd_journal *j, int fd) { + static bool file_has_type_prefix(const char *prefix, const char *filename) { + const char *full, *tilded, *atted; + +- full = strappend(prefix, ".journal"); ++ full = strappenda(prefix, ".journal"); + tilded = strappenda(full, "~"); + atted = strappenda(prefix, "@"); + +-- +1.9.1 + diff --git a/recipes-fixes/systemd/systemd/0001-journald-accept-EPOLLERR-from-dev-kmsg.patch b/recipes-fixes/systemd/systemd/0001-journald-accept-EPOLLERR-from-dev-kmsg.patch new file mode 100644 index 0000000..dacc707 --- /dev/null +++ b/recipes-fixes/systemd/systemd/0001-journald-accept-EPOLLERR-from-dev-kmsg.patch @@ -0,0 +1,70 @@ +From 5843c5ebb4341382ae9c87e93c2c87467e573548 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= +Date: Thu, 19 Sep 2013 16:57:57 -0500 +Subject: [PATCH] journald: accept EPOLLERR from /dev/kmsg + +Also print out unexpected epoll events explictly. +--- + src/journal/journald-server.c | 20 +++++++++++++++----- + 1 file changed, 15 insertions(+), 5 deletions(-) + +Index: systemd-206/src/journal/journald-server.c +=================================================================== +--- systemd-206.orig/src/journal/journald-server.c ++++ systemd-206/src/journal/journald-server.c +@@ -1075,7 +1075,8 @@ int process_event(Server *s, struct epol + ssize_t n; + + if (ev->events != EPOLLIN) { +- log_error("Got invalid event from epoll."); ++ log_error("Got invalid event from epoll for %s: %"PRIx32, ++ "signal fd", ev->events); + return -EIO; + } + +@@ -1124,8 +1125,12 @@ int process_event(Server *s, struct epol + } else if (ev->data.fd == s->dev_kmsg_fd) { + int r; + +- if (ev->events != EPOLLIN) { +- log_error("Got invalid event from epoll."); ++ if (ev->events & EPOLLERR) ++ log_warning("/dev/kmsg buffer overrun, some messages lost."); ++ ++ if (!(ev->events & EPOLLIN)) { ++ log_error("Got invalid event from epoll for %s: %"PRIx32, ++ "/dev/kmsg", ev->events); + return -EIO; + } + +@@ -1139,7 +1144,9 @@ int process_event(Server *s, struct epol + ev->data.fd == s->syslog_fd) { + + if (ev->events != EPOLLIN) { +- log_error("Got invalid event from epoll."); ++ log_error("Got invalid event from epoll for %s: %"PRIx32, ++ ev->data.fd == s->native_fd ? "native fd" : "syslog fd", ++ ev->events); + return -EIO; + } + +@@ -1267,7 +1274,8 @@ int process_event(Server *s, struct epol + } else if (ev->data.fd == s->stdout_fd) { + + if (ev->events != EPOLLIN) { +- log_error("Got invalid event from epoll."); ++ log_error("Got invalid event from epoll for %s: %"PRIx32, ++ "stdout fd", ev->events); + return -EIO; + } + +@@ -1278,7 +1286,8 @@ int process_event(Server *s, struct epol + StdoutStream *stream; + + if ((ev->events|EPOLLIN|EPOLLHUP) != (EPOLLIN|EPOLLHUP)) { +- log_error("Got invalid event from epoll."); ++ log_error("Got invalid event from epoll for %s: %"PRIx32, ++ "stdout stream", ev->events); + return -EIO; + } + diff --git a/recipes-fixes/systemd/systemd/0001-journald-fix-minor-memory-leak.patch b/recipes-fixes/systemd/systemd/0001-journald-fix-minor-memory-leak.patch new file mode 100644 index 0000000..82dc9ff --- /dev/null +++ b/recipes-fixes/systemd/systemd/0001-journald-fix-minor-memory-leak.patch @@ -0,0 +1,23 @@ +From 2ee0591d12b9e725c4585502285fd91cde682d9b Mon Sep 17 00:00:00 2001 +From: Lennart Poettering +Date: Wed, 9 Oct 2013 04:03:45 +0200 +Subject: [PATCH] journald: fix minor memory leak + +--- + src/journal/journal-vacuum.c | 2 ++ + 1 file changed, 2 insertions(+) + +Index: systemd-206/src/journal/journal-vacuum.c +=================================================================== +--- systemd-206.orig/src/journal/journal-vacuum.c ++++ systemd-206/src/journal/journal-vacuum.c +@@ -273,6 +273,9 @@ int journal_directory_vacuum( + log_debug("Deleted empty journal %s/%s.", directory, p); + else if (errno != ENOENT) + log_warning("Failed to delete %s/%s: %m", directory, p); ++ ++ free(p); ++ + continue; + } + diff --git a/recipes-fixes/systemd/systemd_sysmocom-206.inc b/recipes-fixes/systemd/systemd_sysmocom-206.inc index c60cb95..e790729 100644 --- a/recipes-fixes/systemd/systemd_sysmocom-206.inc +++ b/recipes-fixes/systemd/systemd_sysmocom-206.inc @@ -1,3 +1,8 @@ SRC_URI += " \ file://0001-RFC-fsck-Allow-to-specify-the-fsck-repair-option-in-.patch \ + file://0001-journal-fix-hashmap-leak-in-mmap-cache.patch \ + file://0001-journald-fix-minor-memory-leak.patch \ + file://0001-journald-accept-EPOLLERR-from-dev-kmsg.patch \ + file://0001-journal-fix-minor-memory-leak.patch \ + file://0001-Fix-memory-leak-in-stdout-journal-streams.patch \ "