]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virSysinfoParseX86BaseBoard: Free memory upfront if no board detected
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 9 May 2019 13:59:33 +0000 (15:59 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 10 May 2019 11:54:26 +0000 (13:54 +0200)
If no board was detected then VIR_REALLOC_N() done at the end of
the function will actually free the memory (because nborads ==
0), but @boards will be set to a non-NULL pointer. This makes it
unnecessary harder for a caller to see if any board was detected.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virsysinfo.c

index 9e60d1a553667204503d4a87b95eb4838f578695..6c3adc23abfbe2e1cdbc69c47118599b6b268970 100644 (file)
@@ -844,8 +844,12 @@ virSysinfoParseX86BaseBoard(const char *base,
             nboards--;
     }
 
-    /* This is safe, as we can be only shrinking the memory */
-    ignore_value(VIR_REALLOC_N(boards, nboards));
+    if (nboards == 0) {
+        VIR_FREE(boards);
+    } else {
+        /* This is safe, as we can be only shrinking the memory */
+        ignore_value(VIR_REALLOC_N(boards, nboards));
+    }
 
     *baseBoard = boards;
     *nbaseBoard = nboards;