[PATCH 18/25] virMACMapHashDumper: Refactor array addition

Peter Krempa pkrempa at redhat.com
Fri Feb 12 17:55:31 UTC 2021


Use automatic memory freeing and don't check return value of
virJSONValueNewString as it can't fail.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/util/virmacmap.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c
index 521ab89b5b..12df325933 100644
--- a/src/util/virmacmap.c
+++ b/src/util/virmacmap.c
@@ -214,13 +214,11 @@ virMACMapHashDumper(void *payload,
     GSList *next;

     for (next = macs; next; next = next->next) {
-        virJSONValuePtr m = virJSONValueNewString((const char *) next->data);
+        g_autoptr(virJSONValue) m = virJSONValueNewString((const char *) next->data);

-        if (!m ||
-            virJSONValueArrayAppend(arr, m) < 0) {
-            virJSONValueFree(m);
+        if (virJSONValueArrayAppend(arr, m) < 0)
             return -1;
-        }
+        m = NULL;
     }

     if (virJSONValueObjectAppendString(obj, "domain", name) < 0 ||
-- 
2.29.2




More information about the libvir-list mailing list