From: Peter Krempa Date: Thu, 11 Feb 2021 17:29:40 +0000 (+0100) Subject: virNetServerServicePreExecRestart: Refactor memory cleanup X-Git-Tag: v7.1.0-rc1~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0738ac55ec51b2e3f322025cb91c25345a4e492d;p=thirdparty%2Flibvirt.git virNetServerServicePreExecRestart: Refactor memory cleanup Switch to using the 'g_auto*' helpers. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c index 73232e3747..a72277226a 100644 --- a/src/rpc/virnetserverservice.c +++ b/src/rpc/virnetserverservice.c @@ -336,40 +336,32 @@ virNetServerServicePtr virNetServerServiceNewPostExecRestart(virJSONValuePtr obj virJSONValuePtr virNetServerServicePreExecRestart(virNetServerServicePtr svc) { - virJSONValuePtr object = virJSONValueNewObject(); - virJSONValuePtr socks; + g_autoptr(virJSONValue) object = virJSONValueNewObject(); + g_autoptr(virJSONValue) socks = virJSONValueNewArray(); size_t i; if (virJSONValueObjectAppendNumberInt(object, "auth", svc->auth) < 0) - goto error; + return NULL; if (virJSONValueObjectAppendBoolean(object, "readonly", svc->readonly) < 0) - goto error; + return NULL; if (virJSONValueObjectAppendNumberUint(object, "nrequests_client_max", svc->nrequests_client_max) < 0) - goto error; - - socks = virJSONValueNewArray(); - - if (virJSONValueObjectAppend(object, "socks", socks) < 0) { - virJSONValueFree(socks); - goto error; - } + return NULL; for (i = 0; i < svc->nsocks; i++) { - virJSONValuePtr child; + g_autoptr(virJSONValue) child = NULL; if (!(child = virNetSocketPreExecRestart(svc->socks[i]))) - goto error; + return NULL; - if (virJSONValueArrayAppend(socks, child) < 0) { - virJSONValueFree(child); - goto error; - } + if (virJSONValueArrayAppend(socks, child) < 0) + return NULL; + child = NULL; } - return object; + if (virJSONValueObjectAppend(object, "socks", socks) < 0) + return NULL; + socks = NULL; - error: - virJSONValueFree(object); - return NULL; + return g_steal_pointer(&object); }