From nobody Mon Feb 9 10:10:35 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584646585; cv=none; d=zohomail.com; s=zohoarc; b=UkAHnWKwjUvgmE3EJvIhqmeHs7jNgTwZVbigNVJleZvxPa9YPpSiwdRmiiE3Q2E3f3GJLUHgtNgZ/GxBUZBlvknlMy6WuLgkBwgq5akpflWCJn10DlOiOtDK7/BqkI9rUge6MbtZbBKtUKbOm8bQ94ChbLQe35fUWTmx7OeQPsQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584646585; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+YhhIzT0vBsOJ65oMIr4FxNkOVsMmhSj/ncYQIX0XHc=; b=JKkjAp6PTrETKqfwZW8mC/DHGjz+NpkfxHFZYZ8gV8wcczKA/6YULrC2gQ+kI9zrQVej0wyYSaqevqa6yLKRAh/tUOXqOECCsZlKyJhGj4kPZ6k9wPXEgFI7KgMSt6sXhQ5e+H+kF7nSRfw8kRZwy9fRNx5QQ/GC5GikvFl3tto= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1584646585251988.5636061002114; Thu, 19 Mar 2020 12:36:25 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-234-1RAPv9VEO7q5836hL5UB1A-1; Thu, 19 Mar 2020 15:36:21 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 528E4149C2; Thu, 19 Mar 2020 19:36:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E729F5C219; Thu, 19 Mar 2020 19:36:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id AF3FB18089C8; Thu, 19 Mar 2020 19:36:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02JJa86P021171 for ; Thu, 19 Mar 2020 15:36:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id DDCC71001B09; Thu, 19 Mar 2020 19:36:08 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D8C31001B07 for ; Thu, 19 Mar 2020 19:36:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584646583; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=+YhhIzT0vBsOJ65oMIr4FxNkOVsMmhSj/ncYQIX0XHc=; b=hEmSjLt3ldW/ZOiB5Q8OHKbU5hd08sXKjHKymQz9ktYAXGsZr1w1XLdLTLr3mqHb0Kwre8 +UcGKW+dBLjnZFdoZCpcu+OM2rY9xDGM3IzEsBoJ94pDN3Bg/oLvdcHzI9w8LTqcHQCAAW Gn1cnyhympkG83xsByauya5fRNCVimA= X-MC-Unique: 1RAPv9VEO7q5836hL5UB1A-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/6] virJSONValueObjectDeflattenWorker: Refactor cleanup Date: Thu, 19 Mar 2020 20:35:59 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use automatic memory handling to remove the cleanup section. Signed-off-by: Peter Krempa --- src/util/virjson.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index 2d7368b0b6..f308927fa0 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -2055,11 +2055,10 @@ virJSONValueObjectDeflattenWorker(const char *key, void *opaque) { virJSONValuePtr retobj =3D opaque; - virJSONValuePtr newval =3D NULL; + g_autoptr(virJSONValue) newval =3D NULL; virJSONValuePtr existobj; - char **tokens =3D NULL; + VIR_AUTOSTRINGLIST tokens =3D NULL; size_t ntokens =3D 0; - int ret =3D -1; /* non-nested keys only need to be copied */ if (!strchr(key, '.')) { @@ -2075,46 +2074,42 @@ virJSONValueObjectDeflattenWorker(const char *key, if (virJSONValueObjectHasKey(retobj, key)) { virReportError(VIR_ERR_INVALID_ARG, _("can't deflatten colliding key '%s'"), key); - goto cleanup; + return -1; } if (virJSONValueObjectAppend(retobj, key, newval) < 0) - goto cleanup; + return -1; + + newval =3D NULL; return 0; } if (!(tokens =3D virStringSplitCount(key, ".", 2, &ntokens))) - goto cleanup; + return -1; if (ntokens !=3D 2) { virReportError(VIR_ERR_INVALID_ARG, _("invalid nested value key '%s'"), key); - goto cleanup; + return -1; } if (!(existobj =3D virJSONValueObjectGet(retobj, tokens[0]))) { existobj =3D virJSONValueNewObject(); if (virJSONValueObjectAppend(retobj, tokens[0], existobj) < 0) - goto cleanup; + return -1; } else { if (!virJSONValueIsObject(existobj)) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("mixing nested objects and values is forbidde= n in " "JSON deflattening")); - goto cleanup; + return -1; } } - ret =3D virJSONValueObjectDeflattenWorker(tokens[1], value, existobj); - - cleanup: - virStringListFreeCount(tokens, ntokens); - virJSONValueFree(newval); - - return ret; + return virJSONValueObjectDeflattenWorker(tokens[1], value, existobj); } --=20 2.24.1