]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Plug memory leak on virNetDevBridgeGet() sucessful path
authorAlex Jia <ajia@redhat.com>
Wed, 30 Nov 2011 05:57:11 +0000 (13:57 +0800)
committerEric Blake <eblake@redhat.com>
Wed, 30 Nov 2011 23:47:03 +0000 (16:47 -0700)
Detected by Coverity. Leak introduced in commit c1df2c1.

Two bugs here:
1. memory leak on successful parse
2. failure to parse still returned success

Signed-off-by: Alex Jia <ajia@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
src/util/virnetdevbridge.c

index 060445db85194d8f4afdb6b06ed3777d1e4e3548..0440a738fcb5c83d2ea3fb78475d5a142dea8ade 100644 (file)
@@ -161,13 +161,18 @@ static int virNetDevBridgeGet(const char *brname,
 
     if (virFileExists(path)) {
         char *valuestr;
-        if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), &valuestr) < 0)
+        if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long),
+                           &valuestr) < 0)
             goto cleanup;
 
         if (virStrToLong_ul(valuestr, NULL, 10, value) < 0) {
             virReportSystemError(EINVAL,
-                                 _("Unable to get bridge %s %s"), brname, paramname);
+                                 _("Unable to get bridge %s %s"),
+                                 brname, paramname);
+            VIR_FREE(valuestr);
+            goto cleanup;
         }
+        VIR_FREE(valuestr);
     } else {
         struct __bridge_info info;
         unsigned long args[] = { BRCTL_GET_BRIDGE_INFO, (unsigned long)&info, 0, 0 };