]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
fix memory leak in qemuProcessHandleGraphics()
authorWen Congyang <wency@cn.fujitsu.com>
Wed, 30 Mar 2011 07:46:41 +0000 (15:46 +0800)
committerWen Congyang <ghostwcy@gmail.com>
Sun, 3 Apr 2011 01:13:53 +0000 (09:13 +0800)
If strdup("x509dname") or strdup("saslUsername") success, but
strdup(x509dname) or strdup(saslUsername) failed, subject->nidentity
is not the num elements of subject->identities, and we will leak some
memory.

src/qemu/qemu_process.c

index 6c5ae2f702a93d49b76c59abedd87f370af7fdd7..90fcea085e7908bdbcf3c3f79e2dc8321bd9d631 100644 (file)
@@ -544,18 +544,18 @@ qemuProcessHandleGraphics(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
     if (x509dname) {
         if (VIR_REALLOC_N(subject->identities, subject->nidentity+1) < 0)
             goto no_memory;
-        if (!(subject->identities[subject->nidentity].type = strdup("x509dname")) ||
-            !(subject->identities[subject->nidentity].name = strdup(x509dname)))
-            goto no_memory;
         subject->nidentity++;
+        if (!(subject->identities[subject->nidentity-1].type = strdup("x509dname")) ||
+            !(subject->identities[subject->nidentity-1].name = strdup(x509dname)))
+            goto no_memory;
     }
     if (saslUsername) {
         if (VIR_REALLOC_N(subject->identities, subject->nidentity+1) < 0)
             goto no_memory;
-        if (!(subject->identities[subject->nidentity].type = strdup("saslUsername")) ||
-            !(subject->identities[subject->nidentity].name = strdup(saslUsername)))
-            goto no_memory;
         subject->nidentity++;
+        if (!(subject->identities[subject->nidentity-1].type = strdup("saslUsername")) ||
+            !(subject->identities[subject->nidentity-1].name = strdup(saslUsername)))
+            goto no_memory;
     }
 
     virDomainObjLock(vm);