[lxc-devel] [lxc/master] lxclock: fix a small memory leak

tych0 on Github lxc-bot at linuxcontainers.org
Mon Feb 10 15:15:58 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 498 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200210/a1dd03fe/attachment.bin>
-------------- next part --------------
From b8a6a00cc385fc0c6f36c6497f03a3fd40059706 Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho at tycho.ws>
Date: Mon, 10 Feb 2020 08:14:33 -0700
Subject: [PATCH] lxclock: fix a small memory leak

if (!name), we allocate an unnamed semaphore, but if we then fail to
allocate/create the lock, we don't free this semaphore, and we just leak
it.

Signed-off-by: Tycho Andersen <tycho at tycho.ws>
---
 src/lxc/lxclock.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/lxc/lxclock.c b/src/lxc/lxclock.c
index a77951a5b4..318e5bf5a3 100644
--- a/src/lxc/lxclock.c
+++ b/src/lxc/lxclock.c
@@ -169,6 +169,8 @@ struct lxc_lock *lxc_newlock(const char *lxcpath, const char *name)
 	l->type = LXC_LOCK_FLOCK;
 	l->u.f.fname = lxclock_name(lxcpath, name);
 	if (!l->u.f.fname) {
+		if (!name)
+			free(l->u.sem);
 		free(l);
 		l = NULL;
 		goto on_error;


More information about the lxc-devel mailing list