Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > ebe084c140192657f9094e135a84202c > files > 81

libvirt-0.8.2-29.el5.src.rpm

From 4a9afb8bd1fcb839e10ef0242f260bc01ec663bd Mon Sep 17 00:00:00 2001
From: Eric Blake <eblake@redhat.com>
Date: Thu, 27 Oct 2011 15:40:30 -0600
Subject: [PATCH] fixes for several memory leaks
To: libvir-list@redhat.com

https://bugzilla.redhat.com/show_bug.cgi?id=747514

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 5a814012359a74922892737e1e5b1ee94ba74e49)

Conflicts:

	AUTHORS - no need to merge in this conflict magnet
	src/remote/remote_driver.c - commit 3124256 not present, so one
 less hunk is needed
Signed-off-by: Daniel Veillard <veillard@redhat.com>
---
 src/conf/secret_conf.c                 |    3 ++-
 src/nwfilter/nwfilter_gentech_driver.c |    4 ++--
 src/remote/remote_driver.c             |    5 +++++
 src/util/conf.c                        |   17 +++++++++--------
 src/util/storage_file.c                |    7 ++++---
 src/util/xml.c                         |    5 +++--
 tools/virsh.c                          |   11 ++++++++---
 7 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c
index bbdad89..fc4ae82 100644
--- a/src/conf/secret_conf.c
+++ b/src/conf/secret_conf.c
@@ -1,7 +1,7 @@
 /*
  * secret_conf.c: internal <secret> XML handling
  *
- * Copyright (C) 2009 Red Hat, Inc.
+ * Copyright (C) 2009, 2011 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -182,6 +182,7 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
 
  cleanup:
     VIR_FREE(prop);
+    VIR_FREE(uuidstr);
     virSecretDefFree(def);
     xmlXPathFreeContext(ctxt);
     return ret;
diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c
index 4946373..bad8d2b 100644
--- a/src/nwfilter/nwfilter_gentech_driver.c
+++ b/src/nwfilter/nwfilter_gentech_driver.c
@@ -1,6 +1,7 @@
 /*
  * nwfilter_gentech_driver.c: generic technology driver
  *
+ * Copyright (C) 2011 Red Hat, Inc.
  * Copyright (C) 2010 IBM Corp.
  * Copyright (C) 2010 Stefan Berger
  *
@@ -662,8 +663,6 @@ virNWFilterInstantiate(virConnectPtr conn,
         }
 
         virNWFilterUnlockIface(ifname);
-
-        VIR_FREE(ptrs);
     }
 
 err_exit:
@@ -674,6 +673,7 @@ err_exit:
         virNWFilterRuleInstFree(insts[j]);
 
     VIR_FREE(insts);
+    VIR_FREE(ptrs);
 
     virNWFilterHashTableFree(missing_vars);
 
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index e66b65c..e98d6fb 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -472,22 +472,27 @@ doRemoteOpen (virConnectPtr conn,
         for (i = 0; i < vars->n; i++) {
             var = &vars->p[i];
             if (STRCASEEQ (var->name, "name")) {
+                VIR_FREE(name);
                 name = strdup (var->value);
                 if (!name) goto out_of_memory;
                 var->ignore = 1;
             } else if (STRCASEEQ (var->name, "command")) {
+                VIR_FREE(command);
                 command = strdup (var->value);
                 if (!command) goto out_of_memory;
                 var->ignore = 1;
             } else if (STRCASEEQ (var->name, "socket")) {
+                VIR_FREE(sockname);
                 sockname = strdup (var->value);
                 if (!sockname) goto out_of_memory;
                 var->ignore = 1;
             } else if (STRCASEEQ (var->name, "auth")) {
+                VIR_FREE(authtype);
                 authtype = strdup (var->value);
                 if (!authtype) goto out_of_memory;
                 var->ignore = 1;
             } else if (STRCASEEQ (var->name, "netcat")) {
+                VIR_FREE(netcat);
                 netcat = strdup (var->value);
                 if (!netcat) goto out_of_memory;
                 var->ignore = 1;
diff --git a/src/util/conf.c b/src/util/conf.c
index 8682f7b..7f83a1d 100644
--- a/src/util/conf.c
+++ b/src/util/conf.c
@@ -1,7 +1,7 @@
 /**
  * conf.c: parser for a subset of the Python encoded Xen configuration files
  *
- * Copyright (C) 2006, 2007, 2008, 2009, 2010 Red Hat, Inc.
+ * Copyright (C) 2006-2011 Red Hat, Inc.
  *
  * See COPYING.LIB for the License of this software
  *
@@ -643,22 +643,23 @@ virConfParseStatement(virConfParserCtxtPtr ctxt)
 
     SKIP_BLANKS_AND_EOL;
     if (CUR == '#') {
-        return(virConfParseComment(ctxt));
+        return virConfParseComment(ctxt);
     }
     name = virConfParseName(ctxt);
     if (name == NULL)
-        return(-1);
+        return -1;
     SKIP_BLANKS;
     if (CUR != '=') {
         virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("expecting an assignment"));
-        return(-1);
+        VIR_FREE(name);
+        return -1;
     }
     NEXT;
     SKIP_BLANKS;
     value = virConfParseValue(ctxt);
     if (value == NULL) {
         VIR_FREE(name);
-        return(-1);
+        return -1;
     }
     SKIP_BLANKS;
     if (CUR == '#') {
@@ -670,16 +671,16 @@ virConfParseStatement(virConfParserCtxtPtr ctxt)
             virReportOOMError();
             VIR_FREE(name);
             virConfFreeValue(value);
-            return(-1);
+            return -1;
         }
     }
     if (virConfAddEntry(ctxt->conf, name, value, comm) == NULL) {
         VIR_FREE(name);
         virConfFreeValue(value);
         VIR_FREE(comm);
-        return(-1);
+        return -1;
     }
-    return(0);
+    return 0;
 }
 
 /**
diff --git a/src/util/storage_file.c b/src/util/storage_file.c
index 3cd5dbc..530f3e3 100644
--- a/src/util/storage_file.c
+++ b/src/util/storage_file.c
@@ -1,7 +1,7 @@
 /*
  * storage_file.c: file utility functions for FS storage backend
  *
- * Copyright (C) 2007-2010 Red Hat, Inc.
+ * Copyright (C) 2007-2011 Red Hat, Inc.
  * Copyright (C) 2007-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -741,8 +741,9 @@ virStorageFileGetMetadataFromFD(const char *path,
 
     if (format < 0 ||
         format >= VIR_STORAGE_FILE_LAST) {
-        virReportSystemError(EINVAL, _("unknown storage file format %d"), format);
-        return -1;
+        virReportSystemError(EINVAL, _("unknown storage file format %d"),
+                             format);
+        goto cleanup;
     }
 
     ret = virStorageFileGetMetadataFromBuf(format, path, head, len, meta);
diff --git a/src/util/xml.c b/src/util/xml.c
index 750834b..3d3cccc 100644
--- a/src/util/xml.c
+++ b/src/util/xml.c
@@ -105,9 +105,10 @@ virXPathStringLimit(const char *xpath,
 
     if (tmp != NULL && strlen(tmp) >= maxlen) {
         virXMLError(VIR_ERR_INTERNAL_ERROR,
-                    _("\'%s\' value longer than %zd bytes in virXPathStringLimit()"),
+                    _("\'%s\' value longer than %zd bytes"),
                     xpath, maxlen);
-            return NULL;
+        VIR_FREE(tmp);
+        return NULL;
     }
 
     return tmp;
diff --git a/tools/virsh.c b/tools/virsh.c
index 515e558..dfe8647 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -8478,6 +8478,8 @@ cmdCd(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 {
     const char *dir;
     int found;
+    int ret = TRUE;
+    bool dir_malloced = false;
 
     if (!ctl->imode) {
         vshError(ctl, "%s", _("cd: command valid only in interactive mode"));
@@ -8488,16 +8490,19 @@ cmdCd(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     if (!found) {
         uid_t uid = geteuid();
         dir = virGetUserDirectory(uid);
+        dir_malloced = !!dir;
     }
     if (!dir)
         dir = "/";
 
-    if (chdir (dir) == -1) {
+    if (chdir(dir) == -1) {
         vshError(ctl, _("cd: %s: %s"), strerror(errno), dir);
-        return FALSE;
+        ret = FALSE;
     }
 
-    return TRUE;
+    if (dir_malloced)
+        VIR_FREE(dir);
+    return ret;
 }
 
 #endif
-- 
1.7.4.4