]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: fix memory leak in failure path of virCgroupKillRecursiveInternal
authorChen Hanxiao <chenhanxiao@cn.fujitsu.com>
Tue, 13 May 2014 08:01:16 +0000 (16:01 +0800)
committerLaine Stump <laine@laine.org>
Fri, 16 May 2014 11:11:07 +0000 (14:11 +0300)
Don't leak keypath when we fail to kill a process

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
src/util/vircgroup.c

index fce380ab5f6f7ea87462a6ce5d818d4a3625555b..c578bd08c17fd87bb88ccf0f18ef9d64fa8b7396 100644 (file)
@@ -3370,7 +3370,7 @@ virCgroupKillRecursiveInternal(virCgroupPtr group,
     int rc;
     bool killedAny = false;
     char *keypath = NULL;
-    DIR *dp;
+    DIR *dp = NULL;
     virCgroupPtr subgroup = NULL;
     struct dirent *ent;
     int direrr;
@@ -3381,7 +3381,7 @@ virCgroupKillRecursiveInternal(virCgroupPtr group,
         return -1;
 
     if ((rc = virCgroupKillInternal(group, signum, pids)) < 0)
-        return -1;
+        goto cleanup;
     if (rc == 1)
         killedAny = true;
 
@@ -3394,7 +3394,7 @@ virCgroupKillRecursiveInternal(virCgroupPtr group,
         }
         virReportSystemError(errno,
                              _("Cannot open %s"), keypath);
-        return -1;
+        goto cleanup;
     }
 
     while ((direrr = virDirRead(dp, &ent, keypath)) > 0) {
@@ -3429,7 +3429,9 @@ virCgroupKillRecursiveInternal(virCgroupPtr group,
 
  cleanup:
     virCgroupFree(&subgroup);
-    closedir(dp);
+    VIR_FREE(keypath);
+    if (dp)
+        closedir(dp);
 
     return ret;
 }