]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
valgrind: fix memory leak on container new/put
authorDwight Engen <dwight.engen@oracle.com>
Wed, 4 Sep 2013 21:04:51 +0000 (17:04 -0400)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 5 Sep 2013 15:39:10 +0000 (10:39 -0500)
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxclock.c

index dea694183da6f6005c0342f4d440de665f143817..79ebf84a76d79a5a357c4c16808430bf03d60ecf 100644 (file)
@@ -122,6 +122,10 @@ struct lxc_lock *lxc_newlock(const char *lxcpath, const char *name)
        if (!name) {
                l->type = LXC_LOCK_ANON_SEM;
                l->u.sem = lxc_new_unnamed_sem();
+               if (!l->u.sem) {
+                       free(l);
+                       l = NULL;
+               }
                goto out;
        }
 
@@ -248,8 +252,11 @@ void lxc_putlock(struct lxc_lock *l)
                return;
        switch(l->type) {
        case LXC_LOCK_ANON_SEM:
-               if (l->u.sem)
+               if (l->u.sem) {
                        sem_close(l->u.sem);
+                       free(l->u.sem);
+                       l->u.sem = NULL;
+               }
                break;
        case LXC_LOCK_FLOCK:
                process_lock();
@@ -264,6 +271,7 @@ void lxc_putlock(struct lxc_lock *l)
                }
                break;
        }
+       free(l);
 }
 
 int process_lock(void)