From b9ed1b1589a994da70d0a8a673f30e5e24087c2d Mon Sep 17 00:00:00 2001 From: Vojtech Vilimek Date: Tue, 17 Jun 2025 15:22:58 +0200 Subject: [PATCH] CLI: Fix memory leak in cli_listen (fixes #285) --- sysdep/unix/main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c index 85acc2186..deb108c30 100644 --- a/sysdep/unix/main.c +++ b/sysdep/unix/main.c @@ -582,25 +582,30 @@ cli_listen(struct cli_config *cf) if (sk_open_unix(s, cf->name) < 0) { log(L_ERR "Cannot create control socket %s: %m", cf->name); - return NULL; + goto err; } if (cf->uid || cf->gid) if (chown(cf->name, cf->uid, cf->gid) < 0) { log(L_ERR "Cannot chown control socket %s: %m", cf->name); - return NULL; + goto err; } if (chmod(cf->name, cf->mode) < 0) { log(L_ERR "Cannot chmod control socket %s: %m", cf->name); - return NULL; + goto err; } cli_listener_add_tail(&cli_listeners, l); return l; + +err: + rfree(s); + mb_free(l); + return NULL; } static void -- 2.47.3