From: Peter Krempa Date: Fri, 12 Feb 2021 09:55:56 +0000 (+0100) Subject: virJSONValueNewArrayFromBitmap: Refactor cleanup X-Git-Tag: v7.1.0-rc1~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94ab321ffcd987c267db6f816918ff526c72e615;p=thirdparty%2Flibvirt.git virJSONValueNewArrayFromBitmap: Refactor cleanup Use g_autoptr for the JSON value objects and remove the cleanup label and inline freeing of objects. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- diff --git a/src/util/virjson.c b/src/util/virjson.c index adf1cfbcbc..e4d71d3e09 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1241,29 +1241,21 @@ virJSONValueGetArrayAsBitmap(const virJSONValue *val, virJSONValuePtr virJSONValueNewArrayFromBitmap(virBitmapPtr bitmap) { - virJSONValuePtr ret; + g_autoptr(virJSONValue) ret = virJSONValueNewArray(); ssize_t pos = -1; - ret = virJSONValueNewArray(); - if (!bitmap) - return ret; + return g_steal_pointer(&ret); while ((pos = virBitmapNextSetBit(bitmap, pos)) > -1) { - virJSONValuePtr newelem; + g_autoptr(virJSONValue) newelem = virJSONValueNewNumberLong(pos); - if (!(newelem = virJSONValueNewNumberLong(pos)) || - virJSONValueArrayAppend(ret, newelem) < 0) { - virJSONValueFree(newelem); - goto error; - } + if (virJSONValueArrayAppend(ret, newelem) < 0) + return NULL; + newelem = NULL; } - return ret; - - error: - virJSONValueFree(ret); - return NULL; + return g_steal_pointer(&ret); }