[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] Fix several memory leaks



Hi,

This is the revised patch. The changes include dropping two fixes
and revising one along with Chris' and Daniel's suggestions. Other
fixes keep as they were.

  ozaki-r

>From a0ed67d8a5979fb5ab48a30ab840eed212b7cb92 Mon Sep 17 00:00:00 2001
From: Ryota Ozaki <ozaki ryota gmail com>
Date: Thu, 3 Sep 2009 08:31:59 +0900
Subject: [PATCH] Fix some memory leaks

---
 src/domain_conf.c        |    1 +
 src/network_conf.c       |    5 +++--
 src/qemu_conf.c          |   13 ++++++++-----
 src/storage_backend_fs.c |    2 ++
 4 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/domain_conf.c b/src/domain_conf.c
index 1d2cc7c..4b64219 100644
--- a/src/domain_conf.c
+++ b/src/domain_conf.c
@@ -4361,6 +4361,7 @@ int virDomainSaveXML(virConnectPtr conn,
  cleanup:
     if (fd != -1)
         close(fd);
+    VIR_FREE(configFile);
     return ret;
 }

diff --git a/src/network_conf.c b/src/network_conf.c
index bb649a4..58a4f32 100644
--- a/src/network_conf.c
+++ b/src/network_conf.c
@@ -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,
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index 22f5edd..32d6a48 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -1034,7 +1034,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
                          virDomainNetDefPtr net,
                          int qemuCmdFlags)
 {
-    char *brname;
+    char *brname = NULL;
     int err;
     int tapfd = -1;
     int vnet_hdr = 0;
@@ -1053,7 +1053,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);
@@ -1063,7 +1063,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 ||
@@ -1072,7 +1072,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;
@@ -1100,9 +1100,12 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
         }
         if (template_ifname)
             VIR_FREE(net->ifname);
-        return -1;
+        tapfd = -1;
     }

+cleanup:
+    VIR_FREE(brname);
+
     return tapfd;
 }

diff --git a/src/storage_backend_fs.c b/src/storage_backend_fs.c
index ca6d329..11ac48c 100644
--- a/src/storage_backend_fs.c
+++ b/src/storage_backend_fs.c
@@ -1022,6 +1022,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) {
@@ -1029,6 +1030,7 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
         return -1;
     }

+    VIR_FREE(vol->key);
     vol->key = strdup(vol->target.path);
     if (vol->key == NULL) {
         virReportOOMError(conn);
-- 
1.6.0.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]