qemu-config: never call the callback after an error, fix leak
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 5 Jul 2021 17:14:37 +0000 (19:14 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 20 Jul 2021 15:06:28 +0000 (17:06 +0200)
Ensure that the callback to qemu_config_foreach is never called upon
an error, by moving the invocation before the "out" label.

Cc: armbru@redhat.com
Fixes: 3770141139 ("qemu-config: parse configuration files to a QDict", 2021-06-04)
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
util/qemu-config.c

index 84ee6dc4ea58014ad7d7ca8d83a201cefe13888b..7db810f1e024a0c8ffc0bfb983165a1f9b42ca9b 100644 (file)
@@ -417,12 +417,12 @@ static int qemu_config_foreach(FILE *fp, QEMUConfigCB *cb, void *opaque,
         return res;
     }
     res = count;
-out:
     if (qdict) {
         cb(group, qdict, opaque, errp);
-        qobject_unref(qdict);
     }
+out:
     loc_pop(&loc);
+    qobject_unref(qdict);
     return res;
 }