From 9ac5d3fda101faf4bbd79a7957c12e7d519ad427 Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Sun, 7 Apr 2019 12:24:46 -0700 Subject: [PATCH] Merge pull request #2216 from giuseppe/fix-fd-leak conmon: do not leak fd when creating oom file Signed-off-by: Peter Hunt --- conmon/conmon.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/conmon/conmon.c b/conmon/conmon.c index eece04270d3..1bd7ab7aeae 100644 --- a/conmon/conmon.c +++ b/conmon/conmon.c @@ -881,10 +881,12 @@ static gboolean oom_cb(int fd, GIOCondition condition, G_GNUC_UNUSED gpointer us } if (num_read > 0) { + _cleanup_close_ int oom_fd = -1; if (num_read != sizeof(uint64_t)) nwarn("Failed to read full oom event from eventfd"); ninfo("OOM received"); - if (open("oom", O_CREAT, 0666) < 0) { + oom_fd = open("oom", O_CREAT, 0666); + if (oom_fd < 0) { nwarn("Failed to write oom file"); } return G_SOURCE_CONTINUE;