From nobody Tue Feb 10 15:46:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1613152690; cv=none; d=zohomail.com; s=zohoarc; b=Whgsn19RSiR9qJhQBMhBPeMJoB6OJBY/TW/D9UCIT+Nl4y3JE+7BHwSryK8ltCL+8/nJD+xxRxyI1w5a2Bql5SBoUB5DwHU438rf90x2O80WtUX2eNlCb98UYbQgyZd0NCHICDLb683DQmaXGOPi8jGk44yPSSJwtulnrzOD4OE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152690; 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=ZIG9zamsCUZwhbqUduZGmFQ7gEZX1YVbwPAgh9WWeBk=; b=gZVuHGPQzZteJ+u0oeW6oy9QtnEHR1/f/nhIsy3Hz+RDXyYSzSpLloBhjqioJoI623oI4rtVyqIh7hJI6KGJIcmmeefnTVg9nHjN8bRABztLmh3ny/18voZiqu9VW1lBYBIzXnOrGAEdbHyR0gG0hrfUeQeyas1y7OFutfmr8tA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1613152690259560.4499447107642; Fri, 12 Feb 2021 09:58:10 -0800 (PST) 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-169-9L2DGVvqMd-yODFFGW3eOw-1; Fri, 12 Feb 2021 12:57:11 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 04B4118CAA96; Fri, 12 Feb 2021 17:56:37 +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 D53E35D9DB; Fri, 12 Feb 2021 17:56:36 +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 9988918095CD; Fri, 12 Feb 2021 17:56:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11CHuYws010858 for ; Fri, 12 Feb 2021 12:56:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id C0C1471C31; Fri, 12 Feb 2021 17:56:34 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 23A6E7F353 for ; Fri, 12 Feb 2021 17:56:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152685; 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=ZIG9zamsCUZwhbqUduZGmFQ7gEZX1YVbwPAgh9WWeBk=; b=WrTep8XXoU3kqDXrbWUfFZTwH6KmCRdbYP6w9H51QWnbMrMm1FTL39eXrFp4DFawiQBbJ5 Pbr5o7xxS9IOMha+/WAUc0b9CvqjAZFDG1boRGJIL5Ymn527aUct4q281towgE/7WaZwFw /H/CVJkKvpY3XjcDgSKouYyPyeVr6TA= X-MC-Unique: 9L2DGVvqMd-yODFFGW3eOw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 11/25] virJSONValueObjectInsert: Clear @value on successful insertion Date: Fri, 12 Feb 2021 18:55:24 +0100 Message-Id: <04b6754f0c67537c41da3a1cab6def460a814e60.1613152441.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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" The function takes ownership of @value on success so the proper semantics will be to clear out the @value pointer. Convert @value to a double pointer to do this. Signed-off-by: Peter Krempa --- src/util/virjson.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index a509943fde..80ebcb587c 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -577,10 +577,10 @@ virJSONValueNewObject(void) static int virJSONValueObjectInsert(virJSONValuePtr object, const char *key, - virJSONValuePtr value, + virJSONValuePtr *value, bool prepend) { - virJSONObjectPair pair =3D { NULL, value }; + virJSONObjectPair pair =3D { NULL, *value }; int ret =3D -1; if (object->type !=3D VIR_JSON_TYPE_OBJECT) { @@ -604,6 +604,9 @@ virJSONValueObjectInsert(virJSONValuePtr object, object->data.object.npairs, pair); } + if (ret =3D=3D 0) + *value =3D NULL; + VIR_FREE(pair.key); return ret; } @@ -614,7 +617,7 @@ virJSONValueObjectAppend(virJSONValuePtr object, const char *key, virJSONValuePtr value) { - return virJSONValueObjectInsert(object, key, value, false); + return virJSONValueObjectInsert(object, key, &value, false); } @@ -627,10 +630,8 @@ virJSONValueObjectInsertString(virJSONValuePtr object, virJSONValuePtr jvalue =3D virJSONValueNewString(value); if (!jvalue) return -1; - if (virJSONValueObjectInsert(object, key, jvalue, prepend) < 0) { - virJSONValueFree(jvalue); + if (virJSONValueObjectInsert(object, key, &jvalue, prepend) < 0) return -1; - } return 0; } --=20 2.29.2