]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
virsh: Fix resource leaks when editing files.
authorPeter Krempa <pkrempa@redhat.com>
Wed, 19 Sep 2012 09:31:44 +0000 (11:31 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 19 Sep 2012 12:44:42 +0000 (14:44 +0200)
The cleanup path in virsh-edit helper was never reached when the edit
was successful leaking the document in memory as well as the temporary
file.

tools/virsh-edit.c

index 512ac0d861a72123f18258447c14e5f705d230d3..0ed0e8f0cd767ce79aab93cd4fdbeb9cab903c0b 100644 (file)
@@ -68,6 +68,7 @@ do {
     char *doc_edited = NULL;
     char *doc_reread = NULL;
     const char *msg = NULL;
+    bool edit_success = false;
 
     /* Get the XML configuration of the object. */
     doc = (EDIT_GET_XML);
@@ -139,7 +140,7 @@ redefine:
         }
     }
 
-    break;
+    edit_success = true;
 
 edit_cleanup:
     VIR_FREE(doc);
@@ -149,7 +150,9 @@ edit_cleanup:
         unlink (tmp);
         VIR_FREE(tmp);
     }
-    goto cleanup;
+
+    if (!edit_success)
+        goto cleanup;
 
 } while (0);