]> xenbits.xensource.com Git - libvirt.git/commitdiff
Fix numerous memory leaks
authorDaniel P. Berrange <berrange@redhat.com>
Sat, 1 Dec 2007 15:45:25 +0000 (15:45 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Sat, 1 Dec 2007 15:45:25 +0000 (15:45 +0000)
ChangeLog
src/hash.c
src/iptables.c
src/qemu_driver.c
src/remote_internal.c
src/virsh.c

index 11fc36cf816b084873d1a0f3312e2ea3411b96d1..ad5f279de3027075308c375f43ea3e19d3d87797 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sat Dec  1 10:42:34 EST 2007 Daniel P. Berrange <berrange@redhat.com>
+
+       * src/hash.c: reset error object when releasing connection
+       * src/iptables.c: don't strdup() param passed to strcmp()
+       * src/qemu_driver.c: free TLS directory path in driver shutdown
+       * src/remote_internal.c: don't strdup() params for virRaiseError
+       * src/virsh.c: reset global error object at shutdown. Release
+       connection state during abnormal shutdown
+
 Sat Dec  1 10:22:34 EST 2007 Daniel P. Berrange <berrange@redhat.com>
 
        * src/qemu_driver.c: Fix off-by-1 buffer NULL termination in
index 5da1accd5117f53bf43d14fcd09808ecbbe6e896..2b4b6ece6f355434a0847920ef5c662da129ca4d 100644 (file)
@@ -726,6 +726,7 @@ virFreeConnect(virConnectPtr conn) {
         virHashFree(conn->networks, (virHashDeallocator) virNetworkFreeName);
     if (conn->hashes_mux != NULL)
         xmlFreeMutex(conn->hashes_mux);
+    virResetError(&conn->err);
     free(conn);
     return(0);
 }
index 449782b3227bffc33c752d01b383cee550290519..6de6008bb533450258b15095e12a135349bd82f2 100644 (file)
@@ -246,7 +246,7 @@ iptRulesRemove(iptRules *rules,
     int i;
 
     for (i = 0; i < rules->nrules; i++)
-        if (!strcmp(rules->rules[i].rule, strdup(rule)))
+        if (!strcmp(rules->rules[i].rule, rule))
             break;
 
     if (i >= rules->nrules)
index 9614532fbd7c9f901993928443652f1114bb1a23..a6982613ca97c1b0facbe311825a46b59134b3a9 100644 (file)
@@ -341,6 +341,9 @@ qemudShutdown(void) {
     if (qemu_driver->networkAutostartDir)
         free(qemu_driver->networkAutostartDir);
 
+    if (qemu_driver->vncTLSx509certdir)
+        free(qemu_driver->vncTLSx509certdir);
+
     if (qemu_driver->brctl)
         brShutdown(qemu_driver->brctl);
     if (qemu_driver->iptables)
index 40c12c7c04a80f2c1900185c1553023bcd22fc1a..a8227f3a822c97b7b6f41ed40b3779e9845bbc5f 100644 (file)
@@ -3052,20 +3052,13 @@ server_error (virConnectPtr conn, remote_error *err)
     dom = err->dom ? get_nonnull_domain (conn, *err->dom) : NULL;
     net = err->net ? get_nonnull_network (conn, *err->net) : NULL;
 
-    /* These strings are nullable.  OK to ignore the return value
-     * of strdup since these strings are informational.
-     */
-    char *str1 = err->str1 ? strdup (*err->str1) : NULL;
-    char *str2 = err->str2 ? strdup (*err->str2) : NULL;
-    char *str3 = err->str3 ? strdup (*err->str3) : NULL;
-
-    char *message = err->message ? strdup (*err->message) : NULL;
-
     __virRaiseError (conn, dom, net,
                      err->domain, err->code, err->level,
-                     str1, str2, str3,
+                     err->str1 ? *err->str1 : NULL,
+                     err->str2 ? *err->str2 : NULL,
+                     err->str3 ? *err->str3 : NULL,
                      err->int1, err->int2,
-                     "%s", message);
+                     "%s", err->message ? *err->message : NULL);
 }
 
 /* get_nonnull_domain and get_nonnull_network turn an on-wire
index c8bedc14f06e992c7bb78ca23561947455e5c0d8..ccd85be0e1cf6a8959d28fc0dd6d8278247b37fa 100644 (file)
@@ -4780,7 +4780,8 @@ static int
 vshDeinit(vshControl * ctl)
 {
     vshCloseLogFile(ctl);
-
+    if (ctl->name)
+        free(ctl->name);
     if (ctl->conn) {
         if (virConnectClose(ctl->conn) != 0) {
             ctl->conn = NULL;   /* prevent recursive call from vshError() */
@@ -4788,6 +4789,8 @@ vshDeinit(vshControl * ctl)
                      "failed to disconnect from the hypervisor");
         }
     }
+    virResetLastError();
+
     return TRUE;
 }
 
@@ -4985,11 +4988,15 @@ main(int argc, char **argv)
         ctl->name = strdup(defaultConn);
     }
 
-    if (!vshParseArgv(ctl, argc, argv))
+    if (!vshParseArgv(ctl, argc, argv)) {
+        vshDeinit(ctl);
         exit(EXIT_FAILURE);
+    }
 
-    if (!vshInit(ctl))
+    if (!vshInit(ctl)) {
+        vshDeinit(ctl);
         exit(EXIT_FAILURE);
+    }
 
     if (!ctl->imode) {
         ret = vshCommandRun(ctl, ctl->cmd);