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
This commit is contained in:
Holger Hans Peter Freyther 2015-08-26 14:28:27 +02:00
parent 243de8f36e
commit 3a87c6e2f4
6 changed files with 183 additions and 0 deletions

View File

@ -0,0 +1,23 @@
From f92ae4968f070ef0ada61ba7cd585794fac404dd Mon Sep 17 00:00:00 2001
From: Dan McGee <dan@archlinux.org>
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);
}

View File

@ -0,0 +1,37 @@
From 8e6d9397b550f5617fc9231e3a275348cda23c89 Mon Sep 17 00:00:00 2001
From: George McCollister <george.mccollister@gmail.com>
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);

View File

@ -0,0 +1,25 @@
From baabc09191178a1d1a7454cd1b601a98dcb22976 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
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

View File

@ -0,0 +1,70 @@
From 5843c5ebb4341382ae9c87e93c2c87467e573548 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
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;
}

View File

@ -0,0 +1,23 @@
From 2ee0591d12b9e725c4585502285fd91cde682d9b Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
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;
}

View File

@ -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 \
"