From 723a4648dd2885a8bef92673012f72997f103f56 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 13 Feb 2021 22:19:42 +0100 Subject: [PATCH] lib: Avoid a memleak in pidfile_unlink() Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- lib/util/pidfile.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/util/pidfile.c b/lib/util/pidfile.c index bcd25fb4ba3..b7daa089223 100644 --- a/lib/util/pidfile.c +++ b/lib/util/pidfile.c @@ -208,13 +208,12 @@ void pidfile_create(const char *piddir, const char *name) void pidfile_unlink(const char *piddir, const char *name) { + size_t len = strlen(piddir) + strlen(name) + 6; + char pidFile[len]; int ret; - char *pidFile = NULL; - if (asprintf(&pidFile, "%s/%s.pid", piddir, name) < 0) { - DEBUG(0,("ERROR: Out of memory\n")); - exit(1); - } + snprintf(pidFile, sizeof(pidFile), "%s/%s.pid", piddir, name); + ret = unlink(pidFile); if (ret == -1) { DEBUG(0,("Failed to delete pidfile %s. Error was %s\n", -- 2.47.3