]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix several memory leaks
authorRyota Ozaki <ozaki.ryota@gmail.com>
Fri, 4 Sep 2009 13:56:32 +0000 (15:56 +0200)
committerDaniel Veillard <veillard@redhat.com>
Fri, 4 Sep 2009 13:56:32 +0000 (15:56 +0200)
* src/domain_conf.c src/network_conf.c src/qemu_conf.c
  src/storage_backend_fs.c: various problems spotted by valgrind
  through libvirt code

src/domain_conf.c
src/network_conf.c
src/qemu_conf.c
src/storage_backend_fs.c

index 7eb0714222c53dcbc8604d20450f445ed1d53614..8dde5ddf19c0bd66964b1912f82eeb6deb6e8a2d 100644 (file)
@@ -4496,6 +4496,7 @@ int virDomainSaveXML(virConnectPtr conn,
  cleanup:
     if (fd != -1)
         close(fd);
+    VIR_FREE(configFile);
     return ret;
 }
 
index bb649a4aba07acb782e98f419d76c7dd8a49fdb4..58a4f322b44aed2eed2772893a360c6fe2f9022f 100644 (file)
@@ -820,6 +820,7 @@ int virNetworkDeleteConfig(virConnectPtr conn,
 {
     char *configFile = NULL;
     char *autostartLink = NULL;
+    int ret = -1;
 
     if ((configFile = virNetworkConfigFile(conn, configDir, net->def->name)) == NULL)
         goto error;
@@ -836,12 +837,12 @@ int virNetworkDeleteConfig(virConnectPtr conn,
         goto error;
     }
 
-    return 0;
+    ret = 0;
 
 error:
     VIR_FREE(configFile);
     VIR_FREE(autostartLink);
-    return -1;
+    return ret;
 }
 
 char *virNetworkConfigFile(virConnectPtr conn,
index 2c4a37d34f38d92a3d14043dc6b5c93410001b6b..c6b4184ab0eb6edecc702ea00a2e20b2608f2ee4 100644 (file)
@@ -1066,7 +1066,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
                          virDomainNetDefPtr net,
                          int qemuCmdFlags)
 {
-    char *brname;
+    char *brname = NULL;
     int err;
     int tapfd = -1;
     int vnet_hdr = 0;
@@ -1085,7 +1085,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
         if (brname == NULL)
             return -1;
     } else if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
-        brname = net->data.bridge.brname;
+        brname = strdup(net->data.bridge.brname);
     } else {
         qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          _("Network type %d is not supported"), net->type);
@@ -1095,7 +1095,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
     if (!driver->brctl && (err = brInit(&driver->brctl))) {
         virReportSystemError(conn, err, "%s",
                              _("cannot initialize bridge support"));
-        return -1;
+        goto cleanup;
     }
 
     if (!net->ifname ||
@@ -1104,7 +1104,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
         VIR_FREE(net->ifname);
         if (!(net->ifname = strdup("vnet%d"))) {
             virReportOOMError(conn);
-            return -1;
+            goto cleanup;
         }
         /* avoid exposing vnet%d in dumpxml or error outputs */
         template_ifname = 1;
@@ -1132,9 +1132,12 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
         }
         if (template_ifname)
             VIR_FREE(net->ifname);
-        return -1;
+        tapfd = -1;
     }
 
+cleanup:
+    VIR_FREE(brname);
+
     return tapfd;
 }
 
index 82415049cedf22c47f9111cbe1dbe2af981b08a7..5ff0ed88a48f6ac417a58bc2013e978c49f10dcd 100644 (file)
@@ -1056,6 +1056,7 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
 
     vol->type = VIR_STORAGE_VOL_FILE;
 
+    VIR_FREE(vol->target.path);
     if (virAsprintf(&vol->target.path, "%s/%s",
                     pool->def->target.path,
                     vol->name) == -1) {
@@ -1063,6 +1064,7 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
         return -1;
     }
 
+    VIR_FREE(vol->key);
     vol->key = strdup(vol->target.path);
     if (vol->key == NULL) {
         virReportOOMError(conn);