From 1176961e7bccfab432af0a1f13e665f05dfa8616 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sat, 29 Feb 2020 16:40:06 +0100 Subject: [PATCH] plugins: pidfile: Fix memory leak in pidfile_callback() Signed-off-by: Joachim Nilsson --- plugins/pidfile.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/pidfile.c b/plugins/pidfile.c index f0de3bf7..69a7c2c1 100644 --- a/plugins/pidfile.c +++ b/plugins/pidfile.c @@ -176,8 +176,7 @@ static void pidfile_callback(void *arg, int fd, int events) sz = read(fd, buf, buflen - 1); if (sz <= 0) { _pe("invalid inotify event"); - free(buf); - return; + goto done; } buf[sz] = 0; _d("pidfile: Read %zd bytes, processing ...", sz); @@ -207,8 +206,7 @@ static void pidfile_callback(void *arg, int fd, int events) path = malloc(plen); if (!path) { _pe("Failed allocating path buffer for watcher"); - free(buf); - return; + goto done; } snprintf(path, plen, "%s/%s", wde->path, ev->name); _d("pidfile: path is %s", path); @@ -247,6 +245,8 @@ static void pidfile_callback(void *arg, int fd, int events) if (ev->mask & (IN_CREATE | IN_ATTRIB | IN_MODIFY | IN_MOVED_TO)) update_conds(ev->name, ev->mask); } +done: + free(buf); } /*