]> xenbits.xensource.com Git - libvirt.git/commitdiff
Fixed couple of memory leaks wrt to virXXXDestroy APIs, and clarify docs to match...
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 21 May 2008 20:53:30 +0000 (20:53 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 21 May 2008 20:53:30 +0000 (20:53 +0000)
ChangeLog
qemud/remote.c
src/hash.c
src/libvirt.c
src/remote_internal.c
src/virsh.c

index 0fd68a20e6b2fa6a1fcce386fa62f8b854e20194..d4e52be70c78d374f5df8640465c1512c2fd1f79 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Wed May 21 16:24:29 EST 2008 Daniel P. Berrange <berrange@redhat.com>
+
+       Fix up misc memory leaks / incorrect docs (Cole Robinson)
+       * qemud/remote.c: Free the virDomainPtr object in the
+       virDomainDestroy handler to avoid leak
+       * src/hash.c: Added more ref count debug
+       * src/libvirt.c: Clarified docs on virXXXDestroy to
+       match reality
+       * src/remote_internal.c: Free virDomain/Network objects
+       after dispatching RPC error
+       * src/virsh.c: Added some more virDomainFree calls
+
 Wed May 21 15:42:29 EST 2008 Daniel P. Berrange <berrange@redhat.com>
 
        * python/generator.py: Don't free the underlying virDomainPtr
index a97641ae19084f2dcfa073425799f882a4634387..725152e5ff2b87989ab700e28318612cab1d4583 100644 (file)
@@ -940,9 +940,11 @@ remoteDispatchDomainDestroy (struct qemud_server *server ATTRIBUTE_UNUSED,
         return -2;
     }
 
-    if (virDomainDestroy (dom) == -1)
+    if (virDomainDestroy (dom) == -1) {
+        virDomainFree(dom);
         return -1;
-    /* No need to free dom - destroy does it for us */
+    }
+    virDomainFree(dom);
     return 0;
 }
 
index 79421aad437fc09353155c2650e24d6835d5d024..01def44d91261f8db17e34728176c29ae2a96f12 100644 (file)
@@ -842,6 +842,9 @@ __virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid)
             goto error;
         }
         conn->refs++;
+        DEBUG("New hash entry %p", ret);
+    } else {
+        DEBUG("Existing hash entry %p: refs now %d", ret, ret->refs+1);
     }
     ret->refs++;
     pthread_mutex_unlock(&conn->lock);
index 97f6bc37befc3d903b0f5bc9ca485104a860fcbf..9f6df8ebc3d25ea8c156c31bcb3eeedb628c807f 100644 (file)
@@ -1390,10 +1390,9 @@ virDomainLookupByName(virConnectPtr conn, const char *name)
  * @domain: a domain object
  *
  * Destroy the domain object. The running instance is shutdown if not down
- * already and all resources used by it are given back to the hypervisor.
- * The data structure is freed and should not be used thereafter if the
- * call does not return an error.
- * This function may requires privileged access
+ * already and all resources used by it are given back to the hypervisor. This
+ * does not free the associated virDomainPtr object.
+ * This function may require privileged access
  *
  * Returns 0 in case of success and -1 in case of failure.
  */
@@ -3502,10 +3501,9 @@ virNetworkCreate(virNetworkPtr network)
  * @network: a network object
  *
  * Destroy the network object. The running instance is shutdown if not down
- * already and all resources used by it are given back to the hypervisor.
- * The data structure is freed and should not be used thereafter if the
- * call does not return an error.
- * This function may requires privileged access
+ * already and all resources used by it are given back to the hypervisor. This
+ * does not free the associated virNetworkPtr object.
+ * This function may require privileged access
  *
  * Returns 0 in case of success and -1 in case of failure.
  */
index 51e8eb77e92b3a7150821f11c1bc458fa0466aa4..c17b8910fcf6e95872e2bebfe1da1e7cd034c9b3 100644 (file)
@@ -4606,6 +4606,10 @@ server_error (virConnectPtr conn, remote_error *err)
                      err->str3 ? *err->str3 : NULL,
                      err->int1, err->int2,
                      "%s", err->message ? *err->message : NULL);
+    if (dom)
+        virDomainFree(dom);
+    if (net)
+        virNetworkFree(net);
 }
 
 /* get_nonnull_domain and get_nonnull_network turn an on-wire
index 45af630800c29c58e6c93ed73d6faf4d6562263c..234fc363e76f1ce2e1fd7c4bbe445fd7647bcd73 100644 (file)
@@ -1468,9 +1468,9 @@ cmdDestroy(vshControl * ctl, vshCmd * cmd)
     } else {
         vshError(ctl, FALSE, _("Failed to destroy domain %s"), name);
         ret = FALSE;
-        virDomainFree(dom);
     }
 
+    virDomainFree(dom);
     return ret;
 }
 
@@ -2433,9 +2433,9 @@ cmdNetworkDestroy(vshControl * ctl, vshCmd * cmd)
     } else {
         vshError(ctl, FALSE, _("Failed to destroy network %s"), name);
         ret = FALSE;
-        virNetworkFree(network);
     }
 
+    virNetworkFree(network);
     return ret;
 }
 
@@ -3161,9 +3161,9 @@ cmdPoolDestroy(vshControl * ctl, vshCmd * cmd)
     } else {
         vshError(ctl, FALSE, _("Failed to destroy pool %s"), name);
         ret = FALSE;
-        virStoragePoolFree(pool);
     }
 
+    virStoragePoolFree(pool);
     return ret;
 }