From nobody Sun Apr 28 23:58:02 2024 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=1613152564; cv=none; d=zohomail.com; s=zohoarc; b=IBdP6PlrTVAWT7iFOZBlG+e/VXgmkxAZkpWdi8f2nwAdMYm2f84d8UtpjpChM1vLb30+F+KDjTf2/UnFIDGFAIUnWfBwJbcVI1eWCqTB9pJZ3Nv/IGLjdEQ9M8t6rXHXFzyLRlXmI2irHwStFt5LwZrCfqTsMae97RcjZELYfB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152564; 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=ykmMdI/yH+L6NnLWSbBsbSbqs0aC3/ZygE3GDdlSvSU=; b=iL6E96fzbNPxqaFxT7haY8Lz6zyh4LHxNtOuHMFbLvUeCr5s/rYiNxLzgppLPe2ZlnEXY7DZIn/2XB/+ripUaeVK04auwBN3IUJ96qdoZFIA3FGY9QAI9C1/qxb5sg0SPrGD/yINQMEMJUYSaHQoqvKTRzUr3FNLmyh5MY3U9fU= 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 1613152563979120.56596654257169; Fri, 12 Feb 2021 09:56:03 -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-187-MSflDfrSPV61N1ps-DDqqQ-1; Fri, 12 Feb 2021 12:55:58 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6D70DBBEE5; Fri, 12 Feb 2021 17:55:52 +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 1EC7110074E0; Fri, 12 Feb 2021 17:55:50 +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 D661E18095CC; Fri, 12 Feb 2021 17:55:48 +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 11CHtlEU010526 for ; Fri, 12 Feb 2021 12:55:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3C76218813; Fri, 12 Feb 2021 17:55:47 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D03058823 for ; Fri, 12 Feb 2021 17:55:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152561; 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=ykmMdI/yH+L6NnLWSbBsbSbqs0aC3/ZygE3GDdlSvSU=; b=ckGIENbzZ2a2mG+mhLwaXjz/oYAmaGGTAw48FVICEOaDJvZPL997VnEeyFFoczIGJxYraD KB8iWGD5s7Uz5wCqhQiDvWDV6IWfzQ6DEZC5I7xNOFRF+ZvZdFeeRcCswG7jVkNUnrqpMd yrUBv4lYIQps/elg+k0Z1jJdnF+b8Ls= X-MC-Unique: MSflDfrSPV61N1ps-DDqqQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 01/25] virLockDaemonPreExecRestart: Refactor memory cleanup Date: Fri, 12 Feb 2021 18:55:14 +0100 Message-Id: <6adcd92be15dd5abbf8d9e40590256b376925d27.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.84 on 10.5.11.22 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" Switch to using the 'g_auto*' helpers. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/locking/lock_daemon.c | 81 +++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 46 deletions(-) diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 94fe374df6..5913c0cb9c 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -697,87 +697,76 @@ virLockDaemonPreExecRestart(const char *state_file, virNetDaemonPtr dmn, char **argv) { - virJSONValuePtr child; - char *state =3D NULL; - virJSONValuePtr object =3D virJSONValueNewObject(); - char *magic =3D NULL; - virHashKeyValuePairPtr pairs =3D NULL, tmp; - virJSONValuePtr lockspaces; + g_autoptr(virJSONValue) object =3D virJSONValueNewObject(); + g_autoptr(virJSONValue) lockspaces =3D virJSONValueNewArray(); + g_autoptr(virJSONValue) defaultLockspace =3D NULL; + g_autoptr(virJSONValue) daemon =3D NULL; + g_autofree char *state =3D NULL; + g_autofree char *magic =3D NULL; + g_autofree virHashKeyValuePairPtr pairs =3D NULL; + virHashKeyValuePairPtr tmp; VIR_DEBUG("Running pre-restart exec"); - if (!(child =3D virNetDaemonPreExecRestart(dmn))) - goto cleanup; - - if (virJSONValueObjectAppend(object, "daemon", child) < 0) { - virJSONValueFree(child); - goto cleanup; - } - - if (!(child =3D virLockSpacePreExecRestart(lockDaemon->defaultLockspac= e))) - goto cleanup; - - if (virJSONValueObjectAppend(object, "defaultLockspace", child) < 0) { - virJSONValueFree(child); - goto cleanup; - } + if (!(daemon =3D virNetDaemonPreExecRestart(dmn))) + return -1; - lockspaces =3D virJSONValueNewArray(); + if (virJSONValueObjectAppend(object, "daemon", daemon) < 0) + return -1; + daemon =3D NULL; - if (virJSONValueObjectAppend(object, "lockspaces", lockspaces) < 0) { - virJSONValueFree(lockspaces); - goto cleanup; - } + if (!(defaultLockspace =3D virLockSpacePreExecRestart(lockDaemon->defa= ultLockspace))) + return -1; + if (virJSONValueObjectAppend(object, "defaultLockspace", defaultLocksp= ace) < 0) + return -1; + defaultLockspace =3D NULL; tmp =3D pairs =3D virHashGetItems(lockDaemon->lockspaces, NULL, false); while (tmp && tmp->key) { virLockSpacePtr lockspace =3D (virLockSpacePtr)tmp->value; + g_autoptr(virJSONValue) child =3D NULL; if (!(child =3D virLockSpacePreExecRestart(lockspace))) - goto cleanup; + return -1; - if (virJSONValueArrayAppend(lockspaces, child) < 0) { - virJSONValueFree(child); - goto cleanup; - } + if (virJSONValueArrayAppend(lockspaces, child) < 0) + return -1; + child =3D NULL; tmp++; } + if (virJSONValueObjectAppend(object, "lockspaces", lockspaces) < 0) + return -1; + lockspaces =3D NULL; + if (!(magic =3D virLockDaemonGetExecRestartMagic())) - goto cleanup; + return -1; if (virJSONValueObjectAppendString(object, "magic", magic) < 0) - goto cleanup; + return -1; if (!(state =3D virJSONValueToString(object, true))) - goto cleanup; + return -1; VIR_DEBUG("Saving state %s", state); - if (virFileWriteStr(state_file, - state, 0700) < 0) { + if (virFileWriteStr(state_file, state, 0700) < 0) { virReportSystemError(errno, - _("Unable to save state file %s"), - state_file); - goto cleanup; + _("Unable to save state file %s"), state_file= ); + return -1; } if (execvp(argv[0], argv) < 0) { virReportSystemError(errno, "%s", _("Unable to restart self")); - goto cleanup; + return -1; } abort(); /* This should be impossible to reach */ - cleanup: - VIR_FREE(magic); - VIR_FREE(pairs); - VIR_FREE(state); - virJSONValueFree(object); - return -1; + return 0; } --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 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=1613152565; cv=none; d=zohomail.com; s=zohoarc; b=Ocfqw6cqM+nJnSPLe4lqY3LmafmPxPsZwUQV6jdkPnNlpqhlZNlCp70NEw8OOhaa5uCJza6GFN1mowrs/Ln448ujnYGK9aBxKyOfkonBuo2kZydinAQuEjvmOBm8waRT7XjWDIJFRQ75CcU6e7gFgg6h1zvpDb3wmXfdeD/ytEk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152565; 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=MnKqzMoDKrivtVk+8LrMtozufb4zpAkuuDqOCOB/PpY=; b=gFAqTElmY2VBZNFe5fnJpMhdZsGz8S5n0CgPIDsVPRZlVK+SmgCZeKThlRTBpM+e5uPi+dTaw4sxwGdmENjUF8PJoMtV/6M5I0DwB2ACMabR4wMUApREYJaZebijbAGCbAywT90XtXsl/DzIwkdXAuq0Zx8Woa82FmHXwl6jbK8= 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 1613152565675917.4902800123353; Fri, 12 Feb 2021 09:56:05 -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-455-Cfetn3P_NGyGIVmb4255XQ-1; Fri, 12 Feb 2021 12:56:00 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BBA0FBBEE6; Fri, 12 Feb 2021 17:55:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 937C110021AA; Fri, 12 Feb 2021 17:55:52 +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 4F06F4E58E; Fri, 12 Feb 2021 17:55:52 +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 11CHto90010549 for ; Fri, 12 Feb 2021 12:55:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7C65E67CC5; Fri, 12 Feb 2021 17:55:50 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id DDE71679FB for ; Fri, 12 Feb 2021 17:55:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152563; 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=MnKqzMoDKrivtVk+8LrMtozufb4zpAkuuDqOCOB/PpY=; b=QyKFi9A5Sb10KgXomzL++4rXcqY9AOOc37fZRo78+/H01+FcNCSgNwFBAnExq7sdgeVsnd N4JNFudOXWCPsGbgE3xfwKfj2XbOqMJk5Gr6WTA3qpl28hej7ZpGSadZnUbKGQBqk9laou du7t4ItlRwdsS3DWhCesFkfMI+3iP1M= X-MC-Unique: Cfetn3P_NGyGIVmb4255XQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 02/25] virLogDaemonPreExecRestart: Refactor memory cleanup Date: Fri, 12 Feb 2021 18:55:15 +0100 Message-Id: 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.84 on 10.5.11.22 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" Switch to using the 'g_auto*' helpers. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/logging/log_daemon.c | 54 +++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index 770f6dd273..ceffa6a368 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -505,62 +505,54 @@ virLogDaemonPreExecRestart(const char *state_file, virNetDaemonPtr dmn, char **argv) { - virJSONValuePtr child; - char *state =3D NULL; - virJSONValuePtr object =3D virJSONValueNewObject(); - char *magic =3D NULL; + g_autoptr(virJSONValue) object =3D virJSONValueNewObject(); + g_autoptr(virJSONValue) daemon =3D NULL; + g_autoptr(virJSONValue) handler =3D NULL; + g_autofree char *state =3D NULL; + g_autofree char *magic =3D NULL; VIR_DEBUG("Running pre-restart exec"); - if (!(child =3D virNetDaemonPreExecRestart(dmn))) - goto cleanup; + if (!(daemon =3D virNetDaemonPreExecRestart(dmn))) + return -1; - if (virJSONValueObjectAppend(object, "daemon", child) < 0) { - virJSONValueFree(child); - goto cleanup; - } + if (virJSONValueObjectAppend(object, "daemon", daemon) < 0) + return -1; + daemon =3D NULL; if (!(magic =3D virLogDaemonGetExecRestartMagic())) - goto cleanup; + return -1; if (virJSONValueObjectAppendString(object, "magic", magic) < 0) - goto cleanup; - - if (!(child =3D virLogHandlerPreExecRestart(logDaemon->handler))) - goto cleanup; + return -1; - if (virJSONValueObjectAppend(object, "handler", child) < 0) { - virJSONValueFree(child); - goto cleanup; - } + if (!(handler =3D virLogHandlerPreExecRestart(logDaemon->handler))) + return -1; + if (virJSONValueObjectAppend(object, "handler", handler) < 0) + return -1; + handler =3D NULL; if (!(state =3D virJSONValueToString(object, true))) - goto cleanup; + return -1; VIR_DEBUG("Saving state %s", state); - if (virFileWriteStr(state_file, - state, 0700) < 0) { + if (virFileWriteStr(state_file, state, 0700) < 0) { virReportSystemError(errno, - _("Unable to save state file %s"), - state_file); - goto cleanup; + _("Unable to save state file %s"), state_file= ); + return -1; } if (execvp(argv[0], argv) < 0) { virReportSystemError(errno, "%s", _("Unable to restart self")); - goto cleanup; + return -1; } abort(); /* This should be impossible to reach */ - cleanup: - VIR_FREE(magic); - VIR_FREE(state); - virJSONValueFree(object); - return -1; + return 0; } --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1613152582; cv=none; d=zohomail.com; s=zohoarc; b=PkQfckYfVQmmV7TVph0dZBz9SDSjHMZgTUqyLViTMtax6d3kLuSALvvOHruku9cFpuENZJpw3SS+8UfTleVsbf828L7bfeRl6lzvX5dI3bJbIziqAjRpBXoXdXqVDJWf/bm8AM459dmNBMyPp8k97p3W2MhebVjPXUrbrVH8WFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152582; 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=S/UOm1ueGbXM1f9eRhYNC8Ah8eupDwCLTRfT0FNqgvU=; b=SwppE/YBa2WfwXk2KfvLSZ0ZQv0X/IejgopRWGqpDzqzsHz35ail2LfHmMdbwhPb6SQ1cyuS+MoI9Zs46gBOu01eGqnfUsMmz5g0Gy+6QXshRnVclPfEr/86jnAkj27unKQOKA8y9y90xK2JglfMk2VvKEDM/zv1oMBuRpBI6XM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1613152581601717.1223217170369; Fri, 12 Feb 2021 09:56:21 -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-94-Vkej7Ly5O_Cqrhd6lrpkqg-1; Fri, 12 Feb 2021 12:56:14 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 017C8BBEE2; Fri, 12 Feb 2021 17:56:09 +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 D0062757F9; Fri, 12 Feb 2021 17:56:08 +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 95AEF1809C91; Fri, 12 Feb 2021 17:56:08 +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 11CHtq7P010568 for ; Fri, 12 Feb 2021 12:55:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id BE5C167CD0; Fri, 12 Feb 2021 17:55:52 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2279367CC5 for ; Fri, 12 Feb 2021 17:55:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152577; 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=S/UOm1ueGbXM1f9eRhYNC8Ah8eupDwCLTRfT0FNqgvU=; b=OlHhrTxxNtyvBHO+fmcOshjfbneNpIAslYbwDDNWOeTe93cVhy+NmTVNp1NCXg9m5o1/EW 3wmc9nXftzL+EJtF5Ce2OgroIpW8rdmAWDFMAMa8fO7xAPDjvGZ27QR3fz49WdZFA8FQvG xSzSBTauSMVIqUUbuleRjtWoqhOpUo0= X-MC-Unique: Vkej7Ly5O_Cqrhd6lrpkqg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 03/25] virLogHandlerPreExecRestart: Refactor memory cleanup Date: Fri, 12 Feb 2021 18:55:16 +0100 Message-Id: <726fefce944a5bb90a5f44cf09738462b8d02f68.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.11 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" Switch to using the 'g_auto*' helpers. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/logging/log_handler.c | 42 ++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c index a77c1e0250..cacf9584cd 100644 --- a/src/logging/log_handler.c +++ b/src/logging/log_handler.c @@ -608,56 +608,48 @@ virLogHandlerDomainAppendLogFile(virLogHandlerPtr han= dler, virJSONValuePtr virLogHandlerPreExecRestart(virLogHandlerPtr handler) { - virJSONValuePtr ret =3D virJSONValueNewObject(); - virJSONValuePtr files; + g_autoptr(virJSONValue) ret =3D virJSONValueNewObject(); + g_autoptr(virJSONValue) files =3D virJSONValueNewArray(); size_t i; char domuuid[VIR_UUID_STRING_BUFLEN]; - files =3D virJSONValueNewArray(); - - if (virJSONValueObjectAppend(ret, "files", files) < 0) { - virJSONValueFree(files); - goto error; - } - for (i =3D 0; i < handler->nfiles; i++) { - virJSONValuePtr file =3D virJSONValueNewObject(); - - if (virJSONValueArrayAppend(files, file) < 0) { - virJSONValueFree(file); - goto error; - } + g_autoptr(virJSONValue) file =3D virJSONValueNewObject(); if (virJSONValueObjectAppendNumberInt(file, "pipefd", handler->files[i]->pipefd) <= 0) - goto error; + return NULL; if (virJSONValueObjectAppendString(file, "path", virRotatingFileWriterGetPath(ha= ndler->files[i]->file)) < 0) - goto error; + return NULL; if (virJSONValueObjectAppendString(file, "driver", handler->files[i]->driver) < 0) - goto error; + return NULL; if (virJSONValueObjectAppendString(file, "domname", handler->files[i]->domname) < 0) - goto error; + return NULL; virUUIDFormat(handler->files[i]->domuuid, domuuid); if (virJSONValueObjectAppendString(file, "domuuid", domuuid) < 0) - goto error; + return NULL; if (virSetInherit(handler->files[i]->pipefd, true) < 0) { virReportSystemError(errno, "%s", _("Cannot disable close-on-exec flag")); - goto error; + return NULL; } + + if (virJSONValueArrayAppend(files, file) < 0) + return NULL; + file =3D NULL; } - return ret; + if (virJSONValueObjectAppend(ret, "files", files) < 0) + return NULL; + files =3D NULL; - error: - virJSONValueFree(ret); - return NULL; + return g_steal_pointer(&ret); } --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 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=1613152595; cv=none; d=zohomail.com; s=zohoarc; b=UZsuEnr58uE6toMoME3Kl1+GWn2YqqPXurb8zU7f94H3eBZZjkwvrwWszj22VYUrtr1TNNzCz3qCsjARZC9FhInjVvnlRY3snn9o2IGrSXu3k7q1GwRvtzTObIKkyNiOv04HJJNHEZB06HjGjXl2sMyYbTy8xNBtaMciFeXSIgM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152595; 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=VEVMr0+qFmmMiK60hCbRUDQ8Tp5tJI9mmdB0LnDQVVo=; b=e8yWQpRsnp0607k7PnGYB4uljjUdyeK66XHN8K+eIQoNPZNRvNfa1RxgVqYF8PiuUA+C9fH5wvbmT/aT5SOZONHoKe4U0Ld2aDPjyCuVWpTqAmN+picYAgEMghI+WNVWIRWqcZHZdbuzVp2URQfvxtF3XfK45POekfeb2qwCY4U= 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 1613152594767682.5981466858176; Fri, 12 Feb 2021 09:56:34 -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-153-q_HoMYqEMnyTtDr-x73g6g-1; Fri, 12 Feb 2021 12:56:31 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 92C9C101C8DB; Fri, 12 Feb 2021 17:56:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D8FFF6EE5B; Fri, 12 Feb 2021 17:56:19 +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 981C14EEF6; Fri, 12 Feb 2021 17:56:19 +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 11CHuIhX010702 for ; Fri, 12 Feb 2021 12:56:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9DA9467CE2; Fri, 12 Feb 2021 17:56:18 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF72C67CDE for ; Fri, 12 Feb 2021 17:55:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152593; 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=VEVMr0+qFmmMiK60hCbRUDQ8Tp5tJI9mmdB0LnDQVVo=; b=cdKuO9tdWLf4OhnJnE668f8ZrezdgO552LcDC9/DPDdxlJ8PrchrTqzMMjGsEWTOMR+9e9 forqhmlGgV52vxJhSdmEhSmYeGtKBYqhxcWEVogVNU4X2ltneUIPa3SNu3yTWFhdQsI/AG jKFCBOj3TOA9WaHIq97b2WBK7h5noto= X-MC-Unique: q_HoMYqEMnyTtDr-x73g6g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 04/25] virNetDaemonPreExecRestart: Refactor memory cleanup Date: Fri, 12 Feb 2021 18:55:17 +0100 Message-Id: <9d6a07d0504b0e22cd5632fe279a53af9c513fcb.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.12 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" Switch to using the 'g_auto*' helpers. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/rpc/virnetdaemon.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index 2c18da790b..6132615093 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -384,23 +384,18 @@ virJSONValuePtr virNetDaemonPreExecRestart(virNetDaemonPtr dmn) { size_t i =3D 0; - virJSONValuePtr object =3D virJSONValueNewObject(); - virJSONValuePtr srvObj =3D virJSONValueNewObject(); - virHashKeyValuePairPtr srvArray =3D NULL; + g_autoptr(virJSONValue) object =3D virJSONValueNewObject(); + g_autoptr(virJSONValue) srvObj =3D virJSONValueNewObject(); + g_autofree virHashKeyValuePairPtr srvArray =3D NULL; virObjectLock(dmn); - if (virJSONValueObjectAppend(object, "servers", srvObj) < 0) { - virJSONValueFree(srvObj); - goto error; - } - if (!(srvArray =3D virHashGetItems(dmn->servers, NULL, true))) goto error; for (i =3D 0; srvArray[i].key; i++) { virNetServerPtr server =3D virHashLookup(dmn->servers, srvArray[i]= .key); - virJSONValuePtr srvJSON; + g_autoptr(virJSONValue) srvJSON =3D NULL; if (!server) goto error; @@ -409,20 +404,20 @@ virNetDaemonPreExecRestart(virNetDaemonPtr dmn) if (!srvJSON) goto error; - if (virJSONValueObjectAppend(srvObj, srvArray[i].key, srvJSON) < 0= ) { - virJSONValueFree(srvJSON); + if (virJSONValueObjectAppend(srvObj, srvArray[i].key, srvJSON) < 0) goto error; - } + srvJSON =3D NULL; } - VIR_FREE(srvArray); virObjectUnlock(dmn); - return object; + if (virJSONValueObjectAppend(object, "servers", srvObj) < 0) + return NULL; + srvObj =3D NULL; + + return g_steal_pointer(&object); error: - VIR_FREE(srvArray); - virJSONValueFree(object); virObjectUnlock(dmn); return NULL; } --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1613152613; cv=none; d=zohomail.com; s=zohoarc; b=Kqf02xTlQVuSZ23FikRnHbSkhJJ2Na/NagnjS7TG/RrUAIgOdAdMzz0XJggG25qw/lnPsqLeosTIvJp9a5HPmVPzHU9HHADLY1fNO+PGhZtV5Z0c2tG9BX9btChtn9qNF1667BFqm4CJShvxW68S/NPD3Hd1ckwBsCDo4XHDCdg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152613; 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=x78ycrfB0HlinkWuuDwNFakJwIvDkVZSJxQ4k0BtRn4=; b=QIC35aQHA4f5UYicRtpXJwMLqS1J0bZmDRdE2LgFhqT4h5sGFaRl0FADiru4osFl2n4DWkn/kUg/Hovez0PKINCv9SEbTsf2RRYv+5Roe1H5q3uRNcmLXS/LfA9uQzHe9CVgf7oJo5h/GTzx54aso8cFKrvQuw3SbVZDPnTTWZA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1613152613483802.5626697795642; Fri, 12 Feb 2021 09:56:53 -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-594-qwHTrbRZMgaO0YeG6VHjBA-1; Fri, 12 Feb 2021 12:56:49 -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 E542110894F1; Fri, 12 Feb 2021 17:56:29 +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 C09635D9DB; Fri, 12 Feb 2021 17:56:29 +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 81C7B18095CC; Fri, 12 Feb 2021 17:56:29 +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 11CHuRoe010774 for ; Fri, 12 Feb 2021 12:56:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id A16C367CC2; Fri, 12 Feb 2021 17:56:27 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED42268D28 for ; Fri, 12 Feb 2021 17:56:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152611; 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=x78ycrfB0HlinkWuuDwNFakJwIvDkVZSJxQ4k0BtRn4=; b=fBs3cx9m00FO8zV+9ODP15uYGbFKqc1rPxwocuYw7a3zpZPzKZ499Xy/YzVnttOi6IUOcO WlDKcbPWt97gbnQnnqOUF3NY3QIgqlTTk64K5yr8lG7pNfifkZxEVx10ofsgh1D74Ds4by ucYDJ3QecgtEk3a+yJyt2DjKvu5WPbM= X-MC-Unique: qwHTrbRZMgaO0YeG6VHjBA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 05/25] virNetServerServicePreExecRestart: Refactor memory cleanup Date: Fri, 12 Feb 2021 18:55:18 +0100 Message-Id: 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" Switch to using the 'g_auto*' helpers. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/rpc/virnetserverservice.c | 36 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 22 deletions(-) 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 virNetServerServiceNewPostExec= Restart(virJSONValuePtr obj virJSONValuePtr virNetServerServicePreExecRestart(virNetServerServicePtr s= vc) { - virJSONValuePtr object =3D virJSONValueNewObject(); - virJSONValuePtr socks; + g_autoptr(virJSONValue) object =3D virJSONValueNewObject(); + g_autoptr(virJSONValue) socks =3D 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 =3D virJSONValueNewArray(); - - if (virJSONValueObjectAppend(object, "socks", socks) < 0) { - virJSONValueFree(socks); - goto error; - } + return NULL; for (i =3D 0; i < svc->nsocks; i++) { - virJSONValuePtr child; + g_autoptr(virJSONValue) child =3D NULL; if (!(child =3D 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 =3D NULL; } - return object; + if (virJSONValueObjectAppend(object, "socks", socks) < 0) + return NULL; + socks =3D NULL; - error: - virJSONValueFree(object); - return NULL; + return g_steal_pointer(&object); } --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 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=1613152627; cv=none; d=zohomail.com; s=zohoarc; b=UOZMZzn4F/LrOjsez/ta9fbty7HmxwD0DjqyGRzLTuDzBewJlkiF12Q1TqSpQuuzE119FrKRTeAU4Zegcm8LX8Xey7NOl0RPdhoY1JBPlyW+1e5yNlgMiXC6TPDT4nW/pGYZGO4HJCY/v7lHmFBmBjuRRWA2udbN02/n69PU4Cw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152627; 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=SnbwDTb9JS5dqjUjUFae4lQR7ROWDr10IpjFgvGIgRY=; b=FzXfGT1wQvqzLiS9BrVZjeGieZvJratXaUcPu61v9HPgWpcSRFYzoC8I2+cluPLu/65s0SDKc3MJ+syqPjhXXXWHLYGTwz9nZXqJCEoLH9n27N3WQ1l1R1qq7MOhnoP9HVAKxUndCX87uAc02t94FoPsL72L44fYPyqOKPQGIXk= 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 1613152626853962.4292708551344; Fri, 12 Feb 2021 09:57:06 -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-443-LOqDuZZmML-rEvGPsmhb9g-1; Fri, 12 Feb 2021 12:56:57 -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 0EFF3109EC22; Fri, 12 Feb 2021 17:56:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DE6F45D9DB; Fri, 12 Feb 2021 17:56:30 +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 A3B3F57DF9; Fri, 12 Feb 2021 17:56:30 +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 11CHuTv7010798 for ; Fri, 12 Feb 2021 12:56:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id DADED68D2F; Fri, 12 Feb 2021 17:56:28 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F96268D54 for ; Fri, 12 Feb 2021 17:56:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152620; 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=SnbwDTb9JS5dqjUjUFae4lQR7ROWDr10IpjFgvGIgRY=; b=VxOnOtY5hFFMCmlBRjwLDLf3K6s6/pWAyQF2Q4/cp+q5Ok05djnUc+qywcTfv4aR52Yixx yeFoYYjE+yVgYjMaHFePOJVINNlt67/Au4RF9GD8+guNKF2bnBDo/z3hCk89Zp0DzAjAOJ KPRYY1N31OkyUid5gO79MUlH2iM2DBg= X-MC-Unique: LOqDuZZmML-rEvGPsmhb9g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 06/25] virNetServerClientPreExecRestart: Refactor memory cleanup Date: Fri, 12 Feb 2021 18:55:19 +0100 Message-Id: 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" Switch to using the 'g_auto*' helpers. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/rpc/virnetserverclient.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c index 4d01e87e21..0789ad9154 100644 --- a/src/rpc/virnetserverclient.c +++ b/src/rpc/virnetserverclient.c @@ -585,15 +585,14 @@ virNetServerClientPtr virNetServerClientNewPostExecRe= start(virNetServerPtr srv, virJSONValuePtr virNetServerClientPreExecRestart(virNetServerClientPtr cli= ent) { - virJSONValuePtr object =3D virJSONValueNewObject(); - virJSONValuePtr child; + g_autoptr(virJSONValue) object =3D virJSONValueNewObject(); + g_autoptr(virJSONValue) sock =3D NULL; + g_autoptr(virJSONValue) priv =3D NULL; virObjectLock(client); - if (virJSONValueObjectAppendNumberUlong(object, "id", - client->id) < 0) + if (virJSONValueObjectAppendNumberUlong(object, "id", client->id) < 0) goto error; - if (virJSONValueObjectAppendNumberInt(object, "auth", client->auth) < = 0) goto error; if (virJSONValueObjectAppendBoolean(object, "auth_pending", client->au= th_pending) < 0) @@ -608,28 +607,25 @@ virJSONValuePtr virNetServerClientPreExecRestart(virN= etServerClientPtr client) client->conn_time) < 0) goto error; - if (!(child =3D virNetSocketPreExecRestart(client->sock))) + if (!(sock =3D virNetSocketPreExecRestart(client->sock))) goto error; - if (virJSONValueObjectAppend(object, "sock", child) < 0) { - virJSONValueFree(child); + if (virJSONValueObjectAppend(object, "sock", sock) < 0) goto error; - } + sock =3D NULL; - if (!(child =3D client->privateDataPreExecRestart(client, client->priv= ateData))) + if (!(priv =3D client->privateDataPreExecRestart(client, client->priva= teData))) goto error; - if (virJSONValueObjectAppend(object, "privateData", child) < 0) { - virJSONValueFree(child); + if (virJSONValueObjectAppend(object, "privateData", priv) < 0) goto error; - } + priv =3D NULL; virObjectUnlock(client); - return object; + return g_steal_pointer(&object); error: virObjectUnlock(client); - virJSONValueFree(object); return NULL; } --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1613152633; cv=none; d=zohomail.com; s=zohoarc; b=QRlPRhKEmgQIiaTLC2Oy7+dIFPUo1J4+L8u9Wk9EJ0BjBmD0J2MeOtxNkhFvXGnufIYpH3yIRilJZUfWLaWl1wGvRI3JAh7o58+LOssiCWn0oaB09cGOkWNhmQE8mds36lFlePwWZLnJGQJDj3+pbdJgQ8lJ5ri7SjqdtauCW6w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152633; 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=qGyHO52nc9hOoNxByk13ZuT0lRFRrHeSrTn54p4gq+k=; b=dI8OcRHTuBn2nmbb1ZlKa/N7ZGlgr2TS5HinowVofxZ2H0HCc6TvLjE9v0LOWKbxdgxIzZFUnyVqJtL90W8T40bO2Kg5z2qfhIlmA+QH19x2QN/pCcWThVzalSP7QHEqGQ54BMGanaRSLvJhGBok6avB5Qo4Yg4l4BaYURxoiIk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1613152632864672.2424026002985; Fri, 12 Feb 2021 09:57:12 -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-560-5QLKp8R1Mj-mBbTOCQuPow-1; Fri, 12 Feb 2021 12:57:02 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 082C9100A61E; Fri, 12 Feb 2021 17:56:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D2D5A614EB; Fri, 12 Feb 2021 17:56:33 +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 9A4F757DFD; Fri, 12 Feb 2021 17:56:33 +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 11CHuUqN010811 for ; Fri, 12 Feb 2021 12:56:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3F41E5C23D; Fri, 12 Feb 2021 17:56:30 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A44568D53 for ; Fri, 12 Feb 2021 17:56:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152624; 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=qGyHO52nc9hOoNxByk13ZuT0lRFRrHeSrTn54p4gq+k=; b=KPSlkpwr/Onqq3IidxsiFjKirlOTOC03D5y/TCS4Cw6Z6lPPF97uTs6UopGLFXUVZrLNXZ dGnXLGYjtu8ANwLRAG7o+3CI99+coiltUFezWnMyzKezkevntio9D4cKesNcmVmK7CwTKA rVVWNDrLDJbNFSr324sSvluuV4Fep+U= X-MC-Unique: 5QLKp8R1Mj-mBbTOCQuPow-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 07/25] virNetServerPreExecRestart: Drop error reporting from virJSONValueObjectAppend* calls Date: Fri, 12 Feb 2021 18:55:20 +0100 Message-Id: <3f9e7c84195055ae65ca60d90e757ebbe21119a3.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.13 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 functions report errors already and the error can nowadays only happen on programmer errors (if the passed virJSONValue isn't an object), which won't happen. Remove the reporting. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/rpc/virnetserver.c | 42 ++++++++++-------------------------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index f0b866a962..ab8dafb1bb 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -556,51 +556,29 @@ virJSONValuePtr virNetServerPreExecRestart(virNetServ= erPtr srv) virObjectLock(srv); if (virJSONValueObjectAppendNumberUint(object, "min_workers", - virThreadPoolGetMinWorkers(srv-= >workers)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot set min_workers data in JSON document")); + virThreadPoolGetMinWorkers(srv-= >workers)) < 0) goto error; - } if (virJSONValueObjectAppendNumberUint(object, "max_workers", - virThreadPoolGetMaxWorkers(srv-= >workers)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot set max_workers data in JSON document")); + virThreadPoolGetMaxWorkers(srv-= >workers)) < 0) goto error; - } if (virJSONValueObjectAppendNumberUint(object, "priority_workers", - virThreadPoolGetPriorityWorkers= (srv->workers)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot set priority_workers data in JSON documen= t")); + virThreadPoolGetPriorityWorkers= (srv->workers)) < 0) goto error; - } - if (virJSONValueObjectAppendNumberUint(object, "max_clients", srv->ncl= ients_max) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot set max_clients data in JSON document")); + + if (virJSONValueObjectAppendNumberUint(object, "max_clients", srv->ncl= ients_max) < 0) goto error; - } if (virJSONValueObjectAppendNumberUint(object, "max_anonymous_clients", - srv->nclients_unauth_max) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot set max_anonymous_clients data in JSON do= cument")); + srv->nclients_unauth_max) < 0) goto error; - } - if (virJSONValueObjectAppendNumberUint(object, "keepaliveInterval", sr= v->keepaliveInterval) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot set keepaliveInterval data in JSON docume= nt")); + + if (virJSONValueObjectAppendNumberUint(object, "keepaliveInterval", sr= v->keepaliveInterval) < 0) goto error; - } - if (virJSONValueObjectAppendNumberUint(object, "keepaliveCount", srv->= keepaliveCount) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot set keepaliveCount data in JSON document"= )); + if (virJSONValueObjectAppendNumberUint(object, "keepaliveCount", srv->= keepaliveCount) < 0) goto error; - } if (virJSONValueObjectAppendNumberUlong(object, "next_client_id", - srv->next_client_id) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot set next_client_id data in JSON document"= )); + srv->next_client_id) < 0) goto error; - } services =3D virJSONValueNewArray(); --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 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=1613152637; cv=none; d=zohomail.com; s=zohoarc; b=g8hYJ64dzKjMz2U1QWihM2YWUuy8OG9kSMVLu9FyRAVbL+hXxFangVmOmzniWoE5SB03zAaYW9SdshfimAIlfqFHgxm1UDvFNIKgPia748EUNO0pDR5dUAmHRJW3AK6CGYD+D07vxtj56BLNXt3w4EYyey2vKAyuFDVr8d8wb5M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152637; 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=6RzIZynsvA25lG8qgyAcDVprcC3lQisMG+r6TFMRSJ4=; b=jxqVle8aTmBlR1+fEdw5hH7TM8jglNCQFbTMTnQOVRDdrmYYdu73VtkWjf/vQxzzIc4rJbl0bIVmNMqjJqOSJ2B1hsD2Ww3AR8PmGjjZ7BSqvzLWFPKuluCMdk/4w7Z7p3yfN0Fdk1Qj+BiKjo2sXACe4rQiVwymy/75bUt5DVI= 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 1613152636805187.9000558426751; Fri, 12 Feb 2021 09:57:16 -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-343-nX3KHQwDNFy7kQSCIF5NiQ-1; Fri, 12 Feb 2021 12:57:09 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 95429879A15; Fri, 12 Feb 2021 17:56:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7359A614EB; Fri, 12 Feb 2021 17:56:34 +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 3741A57DF9; Fri, 12 Feb 2021 17:56:34 +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 11CHuV8q010828 for ; Fri, 12 Feb 2021 12:56:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id A1FC668D25; Fri, 12 Feb 2021 17:56:31 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FB8F68D2E for ; Fri, 12 Feb 2021 17:56:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152632; 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=6RzIZynsvA25lG8qgyAcDVprcC3lQisMG+r6TFMRSJ4=; b=AGJ6vXMGo+GThZVfWsC/qBTTZ9Tm8gb2wYGO0F5BGpVO0SVBUIFvovGgsgFLmo3HEIRbCK 1PEF+jZVdBlU80fEHQPQRBd3Y2I1xyxC/QtDzwd7SwYgBE23PGPsVLB34+O5QAz9qnU5mu 49E0vmbGMqxKUnCMc2a6zwQm9rFzBCI= X-MC-Unique: nX3KHQwDNFy7kQSCIF5NiQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 08/25] virNetServerPreExecRestart: Refactor memory cleanup Date: Fri, 12 Feb 2021 18:55:21 +0100 Message-Id: <13e1be9b4a89158c22a8d028070ea61861a7aa2c.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.13 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" Switch to using the 'g_auto*' helpers. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/rpc/virnetserver.c | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index ab8dafb1bb..ee402e8ea0 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -548,9 +548,9 @@ virNetServerPtr virNetServerNewPostExecRestart(virJSONV= aluePtr object, virJSONValuePtr virNetServerPreExecRestart(virNetServerPtr srv) { - virJSONValuePtr object =3D virJSONValueNewObject(); - virJSONValuePtr clients; - virJSONValuePtr services; + g_autoptr(virJSONValue) object =3D virJSONValueNewObject(); + g_autoptr(virJSONValue) clients =3D virJSONValueNewArray(); + g_autoptr(virJSONValue) services =3D virJSONValueNewArray(); size_t i; virObjectLock(srv); @@ -580,48 +580,39 @@ virJSONValuePtr virNetServerPreExecRestart(virNetServ= erPtr srv) srv->next_client_id) < 0) goto error; - services =3D virJSONValueNewArray(); - - if (virJSONValueObjectAppend(object, "services", services) < 0) { - virJSONValueFree(services); - goto error; - } - for (i =3D 0; i < srv->nservices; i++) { - virJSONValuePtr child; + g_autoptr(virJSONValue) child =3D NULL; if (!(child =3D virNetServerServicePreExecRestart(srv->services[i]= ))) goto error; - if (virJSONValueArrayAppend(services, child) < 0) { - virJSONValueFree(child); + if (virJSONValueArrayAppend(services, child) < 0) goto error; - } + child =3D NULL; } - clients =3D virJSONValueNewArray(); - - if (virJSONValueObjectAppend(object, "clients", clients) < 0) { - virJSONValueFree(clients); + if (virJSONValueObjectAppend(object, "services", services) < 0) goto error; - } + services =3D NULL; for (i =3D 0; i < srv->nclients; i++) { - virJSONValuePtr child; + g_autoptr(virJSONValue) child =3D NULL; if (!(child =3D virNetServerClientPreExecRestart(srv->clients[i]))) goto error; - if (virJSONValueArrayAppend(clients, child) < 0) { - virJSONValueFree(child); + if (virJSONValueArrayAppend(clients, child) < 0) goto error; - } + child =3D NULL; } + if (virJSONValueObjectAppend(object, "clients", clients) < 0) + goto error; + clients =3D NULL; + virObjectUnlock(srv); - return object; + return g_steal_pointer(&object); error: - virJSONValueFree(object); virObjectUnlock(srv); return NULL; } --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1613152638; cv=none; d=zohomail.com; s=zohoarc; b=YcpLp4V5oI6DnNFK7Wj7bIRgXwqZ9e5PqhvYvDNHYxhVIbs7U7HGOC7RD3aETSjZjn3Af0Zf+VyYzrfIwCYoIOLLeDT87s00hrkifJa0mB27DG0w8G95ghu9/3DI7i2Jdd+mbbe3PNkkDTY2pz63ksgccv9NrGeOaZJkuT0mwr8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152638; 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=xh5MmDGGEsAwDEyLeAntX56sx0s9fwVdbN3A01UoaRs=; b=g3EC7m3D3LuMC8P0DcRJr3x44RGg1dCUFI+0Go5NL304oGY3cVNmPwczfKNrWVGUXWpXDgT9xRctVaNQ9jcY3nW5HoGwU0Z+81oI0xNdqv30l0OKau46EBO9weRSCYjNgWMEMn3DJa5NWSVdokdzIJ7LfAV/UUtkW9rslfD2hlw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1613152637960554.9151431946765; Fri, 12 Feb 2021 09:57:17 -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-290-aR3yHXuRMhSCb7JgAK4Bvg-1; Fri, 12 Feb 2021 12:57:11 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 09F3A1084C84; 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 D889660BE5; 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 9E6AD18095CE; 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 11CHuXL7010834 for ; Fri, 12 Feb 2021 12:56:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id C869D7192B; Fri, 12 Feb 2021 17:56:32 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD27A5C3FD for ; Fri, 12 Feb 2021 17:56:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152636; 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=xh5MmDGGEsAwDEyLeAntX56sx0s9fwVdbN3A01UoaRs=; b=cYOiOICjXmpMVcxycqqz1sUMd4ZpR5VKJwnTrlkSHnBK+KrSVtEnya2ymPTEEkPviFePqC AAin0rAtC3fgG8Iddz+Sf7AjnKV3rW8wTa0WvH+eYYf1TeJt896RjlD5KYt2lCtwJkz/fc zXu7KscqObXamREjxEdBG/B8gezZ/0A= X-MC-Unique: aR3yHXuRMhSCb7JgAK4Bvg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 09/25] virLockSpacePreExecRestart: Refactor memory cleanup Date: Fri, 12 Feb 2021 18:55:22 +0100 Message-Id: <3b14ecf6d2de8ed80fe4aef0bfd231467cc2a248.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.12 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" Switch to using the 'g_auto*' helpers. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virlockspace.c | 51 +++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c index 7df319004e..1b6b51b649 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -418,9 +418,10 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSON= ValuePtr object) virJSONValuePtr virLockSpacePreExecRestart(virLockSpacePtr lockspace) { - virJSONValuePtr object =3D virJSONValueNewObject(); - virJSONValuePtr resources; - virHashKeyValuePairPtr pairs =3D NULL, tmp; + g_autoptr(virJSONValue) object =3D virJSONValueNewObject(); + g_autoptr(virJSONValue) resources =3D virJSONValueNewArray(); + g_autofree virHashKeyValuePairPtr pairs =3D NULL; + virHashKeyValuePairPtr tmp; virMutexLock(&lockspace->lock); @@ -428,25 +429,14 @@ virJSONValuePtr virLockSpacePreExecRestart(virLockSpa= cePtr lockspace) virJSONValueObjectAppendString(object, "directory", lockspace->dir= ) < 0) goto error; - resources =3D virJSONValueNewArray(); - - if (virJSONValueObjectAppend(object, "resources", resources) < 0) { - virJSONValueFree(resources); - goto error; - } tmp =3D pairs =3D virHashGetItems(lockspace->resources, NULL, false); while (tmp && tmp->value) { virLockSpaceResourcePtr res =3D (virLockSpaceResourcePtr)tmp->valu= e; - virJSONValuePtr child =3D virJSONValueNewObject(); - virJSONValuePtr owners =3D NULL; + g_autoptr(virJSONValue) child =3D virJSONValueNewObject(); + g_autoptr(virJSONValue) owners =3D virJSONValueNewArray(); size_t i; - if (virJSONValueArrayAppend(resources, child) < 0) { - virJSONValueFree(child); - goto error; - } - if (virJSONValueObjectAppendString(child, "name", res->name) < 0 || virJSONValueObjectAppendString(child, "path", res->path) < 0 || virJSONValueObjectAppendNumberInt(child, "fd", res->fd) < 0 || @@ -460,34 +450,35 @@ virJSONValuePtr virLockSpacePreExecRestart(virLockSpa= cePtr lockspace) goto error; } - owners =3D virJSONValueNewArray(); - - if (virJSONValueObjectAppend(child, "owners", owners) < 0) { - virJSONValueFree(owners); - goto error; - } - for (i =3D 0; i < res->nOwners; i++) { - virJSONValuePtr owner =3D virJSONValueNewNumberUlong(res->owne= rs[i]); + g_autoptr(virJSONValue) owner =3D virJSONValueNewNumberUlong(r= es->owners[i]); if (!owner) goto error; - if (virJSONValueArrayAppend(owners, owner) < 0) { - virJSONValueFree(owner); + if (virJSONValueArrayAppend(owners, owner) < 0) goto error; - } + owner =3D NULL; } + if (virJSONValueObjectAppend(child, "owners", owners) < 0) + goto error; + owners =3D NULL; + + if (virJSONValueArrayAppend(resources, child) < 0) + goto error; + child =3D NULL; + tmp++; } - VIR_FREE(pairs); + + if (virJSONValueObjectAppend(object, "resources", resources) < 0) + goto error; + resources =3D NULL; virMutexUnlock(&lockspace->lock); return object; error: - VIR_FREE(pairs); - virJSONValueFree(object); virMutexUnlock(&lockspace->lock); return NULL; } --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1613152643; cv=none; d=zohomail.com; s=zohoarc; b=nDRBpej0chg6vOSnuPSQEW0iVcQTdPcecaNPd68G0T9DPZeuiHB6U3IH79YEN1S3ogkw0HIch6nVFbiTM8zAARYw7OZhsRTexhxeq8hh6bxUYyvqpJGS03U+wfszfEpCifKl+r5HN63BFA7o28o0UdQFMMnRtkpWIy1URnBHQVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152643; 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=hLHdoxAEM4AtSNtad8eOgq+LHERsjSOKksebvGAp+xE=; b=RbAgUlfdY1IVmdRGhLqai9RysXB9rzV11fenHONBPx1+3rlMVTuhcu6iWZcqyeKXU1fxmxm4jawL069wDVNvDNf9Ln5JXM/EqePrsVa5wXRAXRNNt7d2l35FIY3ne7cv+SIITbo4n0sKupyKsDncTCyPknI5reiRjrh50aHE5G8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1613152643561779.2985105942583; Fri, 12 Feb 2021 09:57:23 -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-548-ku9JChpTPQ697ULOEU82xQ-1; Fri, 12 Feb 2021 12:57:15 -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 8F2AE81473C; Fri, 12 Feb 2021 17:56:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 655565D9FC; Fri, 12 Feb 2021 17:56:37 +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 2A5A757DFD; Fri, 12 Feb 2021 17:56:37 +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 11CHuY0f010849 for ; Fri, 12 Feb 2021 12:56:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id B8EF47DA4D; Fri, 12 Feb 2021 17:56:33 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id E375A76606 for ; Fri, 12 Feb 2021 17:56:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152639; 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=hLHdoxAEM4AtSNtad8eOgq+LHERsjSOKksebvGAp+xE=; b=PiZ9t7EOSScbDKZPb8HYcVI9aDi3Eny7m50ypdxLeT09yS2RhiRDwNrFrnNFuLCeaVgv9Y 7ZPCDKCgxSD/+xNBmGi4b/UtOeO4EAApkwSZjJ4ufCmlj+FxscnzeHoUfH/VRu4iHHA6d9 we2rYLhHdGlnrPeRpWzdIH9DGeQqnNg= X-MC-Unique: ku9JChpTPQ697ULOEU82xQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 10/25] qemuAgentMakeCommand: Refactor memory cleanup Date: Fri, 12 Feb 2021 18:55:23 +0100 Message-Id: <4c324e1b1f6602f34c7c78cab7bac8bef732e539.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" Switch to using the 'g_auto*' helpers. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_agent.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 51cc00c618..4712aeb529 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1149,31 +1149,26 @@ static virJSONValuePtr G_GNUC_NULL_TERMINATED qemuAgentMakeCommand(const char *cmdname, ...) { - virJSONValuePtr obj =3D virJSONValueNewObject(); - virJSONValuePtr jargs =3D NULL; + g_autoptr(virJSONValue) obj =3D NULL; + g_autoptr(virJSONValue) jargs =3D NULL; va_list args; va_start(args, cmdname); - if (virJSONValueObjectAppendString(obj, "execute", cmdname) < 0) - goto error; - - if (virJSONValueObjectCreateVArgs(&jargs, args) < 0) - goto error; - - if (jargs && - virJSONValueObjectAppend(obj, "arguments", jargs) < 0) - goto error; + if (virJSONValueObjectCreateVArgs(&jargs, args) < 0) { + va_end(args); + return NULL; + } va_end(args); - return obj; + if (virJSONValueObjectCreate(&obj, + "s:execute", cmdname, + "A:arguments", &jargs, + NULL) < 0) + return NULL; - error: - virJSONValueFree(obj); - virJSONValueFree(jargs); - va_end(args); - return NULL; + return g_steal_pointer(&obj); } static virJSONValuePtr --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 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 Reviewed-by: Michal Privoznik --- 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 From nobody Sun Apr 28 23:58:02 2024 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=1613152646; cv=none; d=zohomail.com; s=zohoarc; b=U+PcVjrjJD9IzPpe0ZUP4y/tH/NWnaXLPVa+TvDvLPAJ5O/mvcICY1fKwOjsQq3eqWz0aN1Zz/A9lNaMLEJgmapda0hHEpVkDKKdGoP+HBOFsmvorh74JlSa0MKvHtiEDGTD4yHjSjn+AfU1NvUcdMZz0IWcCHCVZN4j3y4NTdg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152646; 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=uVmRkd4eTCXDzS9T/XwJHjJRnRLzbkIveR35MZphp1Q=; b=jBpU1TtbcYcc4a7noXfbp0d3a71k2WQdu9Doadvucrewox8U2H3UpBQoFoidLUvpPWAF1RogYO/JvwRjK4T8N6LtC4fz/petjeay1Ucpc6J/11F9i9YFAeLY5x3HD+o1xhAg3Kp8fFiLl9yI4LXCAdmmIXqF06nH5NpvOqfTB0s= 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 161315264651724.822987958562635; Fri, 12 Feb 2021 09:57:26 -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-521-M-7DhPypNpaHk5xaZeS6QQ-1; Fri, 12 Feb 2021 12:57:20 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 12D1384A616; Fri, 12 Feb 2021 17:56:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 40A561A8F2; Fri, 12 Feb 2021 17:56:40 +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 B6BBC57DFC; Fri, 12 Feb 2021 17:56:39 +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 11CHuZRP010868 for ; Fri, 12 Feb 2021 12:56:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id DB0CA5C23D; Fri, 12 Feb 2021 17:56:35 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33EB47DED9 for ; Fri, 12 Feb 2021 17:56:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152645; 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=uVmRkd4eTCXDzS9T/XwJHjJRnRLzbkIveR35MZphp1Q=; b=hsKxIpQqMKzDTGm1U4CU/Ul1Tc1JTaaeP6pjrHxIFWuFv7Qj3I3488aP2NTP5nHWEmB/VY T7Vs3fmcP+HmKy5bqAWxsZSPvFGpFWw95cdr1tafG50/dyEXsCclbFzK9mwmiM6yGW9aka 04lOVG3AdsVy8M44RtAZqFIJqO5YSMc= X-MC-Unique: M-7DhPypNpaHk5xaZeS6QQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 12/25] virJSONValueCopy: Don't use virJSONValue(Object|Array)Append Date: Fri, 12 Feb 2021 18:55:25 +0100 Message-Id: <467e2d99e8f4964bba726bf4ca03e3ef5052956d.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.84 on 10.5.11.23 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" We know the exact number of keys or array members for the copied objects so we can pre-allocate the arrays rather than inserting into them in a loop incurring realloc copy penalty. Also virJSONValueCopy now can't fail since all of the functions allocating the different cases use just g_new/g_strdup internally so we can remove the NULL checks from the recursive calls. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virjson.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index 80ebcb587c..d794eed17f 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1530,27 +1530,23 @@ virJSONValueCopy(const virJSONValue *in) switch ((virJSONType) in->type) { case VIR_JSON_TYPE_OBJECT: out =3D virJSONValueNewObject(); + + out->data.object.pairs =3D g_new0(virJSONObjectPair, in->data.obje= ct.npairs); + out->data.object.npairs =3D in->data.object.npairs; + for (i =3D 0; i < in->data.object.npairs; i++) { - virJSONValuePtr val =3D NULL; - if (!(val =3D virJSONValueCopy(in->data.object.pairs[i].value)= )) - goto error; - if (virJSONValueObjectAppend(out, in->data.object.pairs[i].key, - val) < 0) { - virJSONValueFree(val); - goto error; - } + out->data.object.pairs[i].key =3D g_strdup(in->data.object.pai= rs[i].key); + out->data.object.pairs[i].value =3D virJSONValueCopy(in->data.= object.pairs[i].value); } break; case VIR_JSON_TYPE_ARRAY: out =3D virJSONValueNewArray(); + + out->data.array.values =3D g_new0(virJSONValuePtr, in->data.array.= nvalues); + out->data.array.nvalues =3D in->data.array.nvalues; + for (i =3D 0; i < in->data.array.nvalues; i++) { - virJSONValuePtr val =3D NULL; - if (!(val =3D virJSONValueCopy(in->data.array.values[i]))) - goto error; - if (virJSONValueArrayAppend(out, val) < 0) { - virJSONValueFree(val); - goto error; - } + out->data.array.values[i] =3D virJSONValueCopy(in->data.array.= values[i]); } break; @@ -1570,10 +1566,6 @@ virJSONValueCopy(const virJSONValue *in) } return out; - - error: - virJSONValueFree(out); - return NULL; } --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1613152710; cv=none; d=zohomail.com; s=zohoarc; b=OJFbRJfnQ9SfEUC3D28ZiSOx2W1DYLOhJiZZiywPur10rwJaRIsPDSWj3TdJS5Tlpo1zsCifKBk5HGK9PF1SYCmBMAxcI2TEUzIQlYgBqL9eTQ03vaPBAJUBkj6mTszvpQdi8+4Xnq2b6kFYfeE7r3OWDQNJwZRTFFF6Yuvwqow= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152710; 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=/VtsorEWFyoZVnlFGPRFrM9GQ5oKQ+1JTjENZRGijPk=; b=bRG5Lzjc9qApH0rtvGRCoShvIgtFWO6xsPhAYxmKC9KhV6Tw3ieEIwXsdXvMdQS+mDJsktHS+97NaZDOX5gfnvta807VCY9HtSMqvRBZl1bYVedFZ2Z7zkUyjvjVC7rYwAfBQx4198sYOgKfqSphwFQFFHv7RoaCGnZev+raJMA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1613152710517943.3275630229158; Fri, 12 Feb 2021 09:58:30 -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-39-iEEY6WL5PymihCUMbi_30Q-1; Fri, 12 Feb 2021 12:57:22 -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 D57F091116; Fri, 12 Feb 2021 17:56:42 +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 B3ACC1B5C1; Fri, 12 Feb 2021 17:56:42 +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 75A221809C8F; Fri, 12 Feb 2021 17:56:42 +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 11CHuaDJ010877 for ; Fri, 12 Feb 2021 12:56:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id EE9AC17258; Fri, 12 Feb 2021 17:56:36 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58D395C23D for ; Fri, 12 Feb 2021 17:56:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152707; 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=/VtsorEWFyoZVnlFGPRFrM9GQ5oKQ+1JTjENZRGijPk=; b=DF2TTU/j3HBJ+ApVwOfKyrOh+wqACW3SZ9ZaMe8W5yx8yuLZsx9b6Qt8hSafUXoOsbG/Wd I2yeGCYcBpcC643sartmfR9gkx7+Lbirt+Xl9BEURErXRyRrZIlZe1hBD3JUFECdJTwswO wHAHj3K+y7bYE+OickgM6V96A96ov2w= X-MC-Unique: iEEY6WL5PymihCUMbi_30Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 13/25] virJSONValue(Array|Object)Append*: Simplify handling of appended object Date: Fri, 12 Feb 2021 18:55:26 +0100 Message-Id: <4ddfdd27b97cdb13abf922cd85ef6109f458744e.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" Use g_autofree for the pointer of the added object and remove the NULL checks for values returned by virJSONValueNew* (except virJSONValueNewNumberDouble) since they can't fail nowadays. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virjson.c | 88 ++++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 46 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index d794eed17f..adf1cfbcbc 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -676,13 +676,12 @@ virJSONValueObjectAppendNumberInt(virJSONValuePtr obj= ect, const char *key, int number) { - virJSONValuePtr jvalue =3D virJSONValueNewNumberInt(number); - if (!jvalue) - return -1; - if (virJSONValueObjectAppend(object, key, jvalue) < 0) { - virJSONValueFree(jvalue); + g_autoptr(virJSONValue) jvalue =3D virJSONValueNewNumberInt(number); + + if (virJSONValueObjectAppend(object, key, jvalue) < 0) return -1; - } + jvalue =3D NULL; + return 0; } @@ -692,13 +691,12 @@ virJSONValueObjectAppendNumberUint(virJSONValuePtr ob= ject, const char *key, unsigned int number) { - virJSONValuePtr jvalue =3D virJSONValueNewNumberUint(number); - if (!jvalue) - return -1; - if (virJSONValueObjectAppend(object, key, jvalue) < 0) { - virJSONValueFree(jvalue); + g_autoptr(virJSONValue) jvalue =3D virJSONValueNewNumberUint(number); + + if (virJSONValueObjectAppend(object, key, jvalue) < 0) return -1; - } + jvalue =3D NULL; + return 0; } @@ -708,13 +706,12 @@ virJSONValueObjectAppendNumberLong(virJSONValuePtr ob= ject, const char *key, long long number) { - virJSONValuePtr jvalue =3D virJSONValueNewNumberLong(number); - if (!jvalue) - return -1; - if (virJSONValueObjectAppend(object, key, jvalue) < 0) { - virJSONValueFree(jvalue); + g_autoptr(virJSONValue) jvalue =3D virJSONValueNewNumberLong(number); + + if (virJSONValueObjectAppend(object, key, jvalue) < 0) return -1; - } + jvalue =3D NULL; + return 0; } @@ -724,13 +721,12 @@ virJSONValueObjectAppendNumberUlong(virJSONValuePtr o= bject, const char *key, unsigned long long number) { - virJSONValuePtr jvalue =3D virJSONValueNewNumberUlong(number); - if (!jvalue) - return -1; - if (virJSONValueObjectAppend(object, key, jvalue) < 0) { - virJSONValueFree(jvalue); + g_autoptr(virJSONValue) jvalue =3D virJSONValueNewNumberUlong(number); + + if (virJSONValueObjectAppend(object, key, jvalue) < 0) return -1; - } + jvalue =3D NULL; + return 0; } @@ -740,13 +736,16 @@ virJSONValueObjectAppendNumberDouble(virJSONValuePtr = object, const char *key, double number) { - virJSONValuePtr jvalue =3D virJSONValueNewNumberDouble(number); + g_autoptr(virJSONValue) jvalue =3D virJSONValueNewNumberDouble(number); + + /* virJSONValueNewNumberDouble may return NULL if locale setting fails= */ if (!jvalue) return -1; - if (virJSONValueObjectAppend(object, key, jvalue) < 0) { - virJSONValueFree(jvalue); + + if (virJSONValueObjectAppend(object, key, jvalue) < 0) return -1; - } + jvalue =3D NULL; + return 0; } @@ -756,13 +755,12 @@ virJSONValueObjectAppendBoolean(virJSONValuePtr objec= t, const char *key, int boolean_) { - virJSONValuePtr jvalue =3D virJSONValueNewBoolean(boolean_); - if (!jvalue) - return -1; - if (virJSONValueObjectAppend(object, key, jvalue) < 0) { - virJSONValueFree(jvalue); + g_autoptr(virJSONValue) jvalue =3D virJSONValueNewBoolean(boolean_); + + if (virJSONValueObjectAppend(object, key, jvalue) < 0) return -1; - } + jvalue =3D NULL; + return 0; } @@ -771,13 +769,12 @@ int virJSONValueObjectAppendNull(virJSONValuePtr object, const char *key) { - virJSONValuePtr jvalue =3D virJSONValueNewNull(); - if (!jvalue) - return -1; - if (virJSONValueObjectAppend(object, key, jvalue) < 0) { - virJSONValueFree(jvalue); + g_autoptr(virJSONValue) jvalue =3D virJSONValueNewNull(); + + if (virJSONValueObjectAppend(object, key, jvalue) < 0) return -1; - } + jvalue =3D NULL; + return 0; } @@ -806,13 +803,12 @@ int virJSONValueArrayAppendString(virJSONValuePtr object, const char *value) { - virJSONValuePtr jvalue =3D virJSONValueNewString(value); - if (!jvalue) - return -1; - if (virJSONValueArrayAppend(object, jvalue) < 0) { - virJSONValueFree(jvalue); + g_autoptr(virJSONValue) jvalue =3D virJSONValueNewString(value); + + if (virJSONValueArrayAppend(object, jvalue) < 0) return -1; - } + jvalue =3D NULL; + return 0; } --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1613152642; cv=none; d=zohomail.com; s=zohoarc; b=EQWERMjpqo3rzeCtQhCsUy8/qNNapwCJQ6PG1EsvWqEIOEtCE9wOYla3rlKFgO8K2pIwmozpIGwWM3lDCgrMuAW/v4470tD5ULWQw00FXCXLN6LEeNZpFlWK36PKWFnSgm/AZ7HrRJctcJQ3nH4su07LHuEhliTlMhR/PpL0aD8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152642; 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=L7DzOAZRcupOATo9w41tJ5iAltKmvngeMNl8heo8R7M=; b=fbN3im2LCi4+94/OAe+ABYlkOlR4k6ljYyLwb4VmF74kLRXkE8WzRySHvB/bXiJEteQlZ4iAZqUgo+PG7BUfuTzcSnXkU4f3gTrq6bHY3HPl8JJ+9dO9fQfA/BgtIQPYt90KTO0/uNdU71iRuK0QaukvPfYCueMK7ORmQvBFBqI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1613152642216791.8671943769206; Fri, 12 Feb 2021 09:57:22 -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-576-3Zk612D8OnOd7W2w6t43fQ-1; Fri, 12 Feb 2021 12:57:14 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1EE851087D62; Fri, 12 Feb 2021 17:56:40 +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 EC9F460C17; Fri, 12 Feb 2021 17:56:39 +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 B01E61809C90; Fri, 12 Feb 2021 17:56:39 +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 11CHucH4010894 for ; Fri, 12 Feb 2021 12:56:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1E6FE5C8BE; Fri, 12 Feb 2021 17:56:38 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 660BB5C3E0 for ; Fri, 12 Feb 2021 17:56:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152638; 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=L7DzOAZRcupOATo9w41tJ5iAltKmvngeMNl8heo8R7M=; b=ObFW6yuHO6OXAyOyt0XLdUHxteOX26SaHx/6G5Kx1TTOi5ghk1pWMD1KI/wMCdC+7HjLlE NZDUn7XQMIoonpmgRdjrkbLXGDHB5JB0Ycl0fk0G1q3cNXHkMWbxUakEFgszE/JL2SZKcM MPGvae7djSUDAR6pkIigPVA7XILJNyY= X-MC-Unique: 3Zk612D8OnOd7W2w6t43fQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 14/25] virJSONValueNewArrayFromBitmap: Refactor cleanup Date: Fri, 12 Feb 2021 18:55:27 +0100 Message-Id: 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.12 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" 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 --- src/util/virjson.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) 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 *va= l, virJSONValuePtr virJSONValueNewArrayFromBitmap(virBitmapPtr bitmap) { - virJSONValuePtr ret; + g_autoptr(virJSONValue) ret =3D virJSONValueNewArray(); ssize_t pos =3D -1; - ret =3D virJSONValueNewArray(); - if (!bitmap) - return ret; + return g_steal_pointer(&ret); while ((pos =3D virBitmapNextSetBit(bitmap, pos)) > -1) { - virJSONValuePtr newelem; + g_autoptr(virJSONValue) newelem =3D virJSONValueNewNumberLong(pos); - if (!(newelem =3D virJSONValueNewNumberLong(pos)) || - virJSONValueArrayAppend(ret, newelem) < 0) { - virJSONValueFree(newelem); - goto error; - } + if (virJSONValueArrayAppend(ret, newelem) < 0) + return NULL; + newelem =3D NULL; } - return ret; - - error: - virJSONValueFree(ret); - return NULL; + return g_steal_pointer(&ret); } --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 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=1613152656; cv=none; d=zohomail.com; s=zohoarc; b=I5lLrA5qRGPOU9RlEBUksnmoymD2j9xlyLPCwcXgpDzGBcpDJTZB4zT7LuwWh0NWKt/y9PvV0noasAOtYTTqVMLg0Deq00LTKRYmYgvDCb/0rIKxBqEPZWNsmq1jXI1czAkx9BCifinQE1H2HjVYsvVwfCBxlc8qLYKYseqfF28= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152656; 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=pjoUI/kEw+Cjh6FJS2jaHW13F6YEghKMVJ96SfNIWb8=; b=a+VVSMAk/Y8wbUziUy9vn1Y8m8z71dtKE8u7+v7Cn3PbpgZsnKdV/UCuytun1Z0s4ZMZkpxUAuLCLHrv0+CPH6gtPFFiyqDs6FqRVTXBjx4dQQZAZ7JmsUrVeeszKNPl5S24dv5/fMxqGk8nptyaPwTohaxhWRuVHl68azY26Ik= 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 1613152656349319.5518027142017; Fri, 12 Feb 2021 09:57:36 -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-37-V09Q1gUuPfWrO7NmRS6JZg-1; Fri, 12 Feb 2021 12:57:32 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3C936193F572; Fri, 12 Feb 2021 17:56:43 +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 19450614EB; Fri, 12 Feb 2021 17:56:43 +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 CCB9818095C9; Fri, 12 Feb 2021 17:56:42 +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 11CHudAw010907 for ; Fri, 12 Feb 2021 12:56:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id 40CE55C3E0; Fri, 12 Feb 2021 17:56:39 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E1EB5C23D for ; Fri, 12 Feb 2021 17:56:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152655; 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=pjoUI/kEw+Cjh6FJS2jaHW13F6YEghKMVJ96SfNIWb8=; b=TJVn/4Um92SfqoimwABfu5bTnNvtZFwZx7su2X6EegxAJO/2uZnJlG0geEhngkC2pFekWP nly5pShGFzH+huwttu+TogCRY3AMxSJNTALtl8cstjB4b3vBaSpfOPlC9moJxbh1DJ0zW8 yAFzIlxmJB/+n+EuDMiIR7oMGBPM5T0= X-MC-Unique: V09Q1gUuPfWrO7NmRS6JZg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 15/25] virJSONValueObjectAddVArgs: Use autofree for the temporary bitmap Date: Fri, 12 Feb 2021 18:55:28 +0100 Message-Id: <416b66cca918a57a4b07cdca085ca3d572fc618f.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.13 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" Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virjson.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index e4d71d3e09..7b52525797 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -305,7 +305,7 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj, case 'M': case 'm': { virBitmapPtr map =3D va_arg(args, virBitmapPtr); - virJSONValuePtr jsonMap; + g_autoptr(virJSONValue) jsonMap =3D NULL; if (!map) { if (type =3D=3D 'M') @@ -321,7 +321,8 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj, return -1; if ((rc =3D virJSONValueObjectAppend(obj, key, jsonMap)) < 0) - virJSONValueFree(jsonMap); + return -1; + jsonMap =3D NULL; } break; default: --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1613152656; cv=none; d=zohomail.com; s=zohoarc; b=TZ4/xDHPBwMInpCQcQ2B+UKqmRWmKzmkLlqiB+lyBxona/gHPkqOxHv1g2xLhBGAGyHn5+OGjLSJD0Iwehh2XaxhEqjCTmCy7ffbUv2KwI7xNCG0UDMrKBF7m9syKHzmOCWAFocxrc5iIEcisyPLihooNO1CAZx8F6CIngKlCl8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152656; 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=RwqIiRGLTu/WVFv6v/cyeGM3WUBJU3IljRsoINHebLY=; b=c38jZjMrGDUqKo5kYZymKqkfriF2JoWpIKhCpfmzR4xLLRYEHN2DZQd8jBrjlLf6qxfQRSqcHkFJ1rH2ppPDX0dr6z80fK3ffqGPbbHIZj8rrQRqPklDR6T3LQSWybdtjKI0CREl+H3Om8+P+ls0gY/j9/jsi6SvppaTOjx7LmQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1613152655650477.13036768639347; Fri, 12 Feb 2021 09:57:35 -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-274-SqBLnx5nN8KM0htQaRZTeA-1; Fri, 12 Feb 2021 12:57:30 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A1EE185EE9A; Fri, 12 Feb 2021 17:56:46 +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 B6D6EE150; Fri, 12 Feb 2021 17:56:45 +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 7B7F51809C8F; Fri, 12 Feb 2021 17:56:45 +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 11CHueB8010927 for ; Fri, 12 Feb 2021 12:56:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id AD36B5C23D; Fri, 12 Feb 2021 17:56:40 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB59F5C8AD for ; Fri, 12 Feb 2021 17:56:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152654; 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=RwqIiRGLTu/WVFv6v/cyeGM3WUBJU3IljRsoINHebLY=; b=U4N+x0HxP0htkyGu/3ry//ulUnGS7LbojgPmxBo7/tBaZ3e1Q7m14gvZ/J6DMuJsLuKJq+ Elo/6dQGDOwZoZV4Yyc1rLnDXxLhiB543NGsiXPojw+NcNAseQne9RQtbgdG+CanMeJZAU N05n1dMdZUb1KrS5DL/jQPiNBso+LNs= X-MC-Unique: SqBLnx5nN8KM0htQaRZTeA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 16/25] virJSONValueObjectAppend: Clear pointer when taking ownership of passed value Date: Fri, 12 Feb 2021 18:55:29 +0100 Message-Id: <60b6d2bbba450aadef813fa347a6343891d9f5be.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.84 on 10.5.11.23 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 parent object takes ownership of the inserted value once all checks pass. Don't make the callers second-guess when that happens and modify the function to take a double pointer so that it can be cleared once the ownership is taken. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/locking/lock_daemon.c | 9 +++---- src/logging/log_daemon.c | 6 ++--- src/logging/log_handler.c | 3 +-- src/node_device/node_device_driver.c | 2 +- src/qemu/qemu_block.c | 3 +-- src/qemu/qemu_firmware.c | 23 +++++----------- src/qemu/qemu_monitor_json.c | 22 ++++++---------- src/rpc/virnetdaemon.c | 6 ++--- src/rpc/virnetserver.c | 6 ++--- src/rpc/virnetserverclient.c | 6 ++--- src/rpc/virnetserverservice.c | 3 +-- src/util/virjson.c | 39 ++++++++++++---------------- src/util/virjson.h | 4 ++- src/util/virlockspace.c | 6 ++--- src/util/virmacmap.c | 3 +-- 15 files changed, 52 insertions(+), 89 deletions(-) diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 5913c0cb9c..26905a462b 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -711,16 +711,14 @@ virLockDaemonPreExecRestart(const char *state_file, if (!(daemon =3D virNetDaemonPreExecRestart(dmn))) return -1; - if (virJSONValueObjectAppend(object, "daemon", daemon) < 0) + if (virJSONValueObjectAppend(object, "daemon", &daemon) < 0) return -1; - daemon =3D NULL; if (!(defaultLockspace =3D virLockSpacePreExecRestart(lockDaemon->defa= ultLockspace))) return -1; - if (virJSONValueObjectAppend(object, "defaultLockspace", defaultLocksp= ace) < 0) + if (virJSONValueObjectAppend(object, "defaultLockspace", &defaultLocks= pace) < 0) return -1; - defaultLockspace =3D NULL; tmp =3D pairs =3D virHashGetItems(lockDaemon->lockspaces, NULL, false); while (tmp && tmp->key) { @@ -737,9 +735,8 @@ virLockDaemonPreExecRestart(const char *state_file, tmp++; } - if (virJSONValueObjectAppend(object, "lockspaces", lockspaces) < 0) + if (virJSONValueObjectAppend(object, "lockspaces", &lockspaces) < 0) return -1; - lockspaces =3D NULL; if (!(magic =3D virLockDaemonGetExecRestartMagic())) return -1; diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index ceffa6a368..cc0b96ea05 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -516,9 +516,8 @@ virLogDaemonPreExecRestart(const char *state_file, if (!(daemon =3D virNetDaemonPreExecRestart(dmn))) return -1; - if (virJSONValueObjectAppend(object, "daemon", daemon) < 0) + if (virJSONValueObjectAppend(object, "daemon", &daemon) < 0) return -1; - daemon =3D NULL; if (!(magic =3D virLogDaemonGetExecRestartMagic())) return -1; @@ -529,9 +528,8 @@ virLogDaemonPreExecRestart(const char *state_file, if (!(handler =3D virLogHandlerPreExecRestart(logDaemon->handler))) return -1; - if (virJSONValueObjectAppend(object, "handler", handler) < 0) + if (virJSONValueObjectAppend(object, "handler", &handler) < 0) return -1; - handler =3D NULL; if (!(state =3D virJSONValueToString(object, true))) return -1; diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c index cacf9584cd..d649c4d132 100644 --- a/src/logging/log_handler.c +++ b/src/logging/log_handler.c @@ -647,9 +647,8 @@ virLogHandlerPreExecRestart(virLogHandlerPtr handler) file =3D NULL; } - if (virJSONValueObjectAppend(ret, "files", files) < 0) + if (virJSONValueObjectAppend(ret, "files", &files) < 0) return NULL; - files =3D NULL; return g_steal_pointer(&ret); } diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 51b20848ce..d946e64ad6 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -610,7 +610,7 @@ nodeDeviceDefToMdevctlConfig(virNodeDeviceDefPtr def, c= har **buf) return -1; } - if (virJSONValueObjectAppend(json, "attrs", g_steal_pointer(&attri= butes)) < 0) + if (virJSONValueObjectAppend(json, "attrs", &attributes) < 0) return -1; } diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 3d88e701b2..1df51ba97b 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -1097,9 +1097,8 @@ qemuBlockStorageSourceGetBlockdevGetCacheProps(virSto= rageSourcePtr src, NULL) < 0) return -1; - if (virJSONValueObjectAppend(props, "cache", cacheobj) < 0) + if (virJSONValueObjectAppend(props, "cache", &cacheobj) < 0) return -1; - cacheobj =3D NULL; return 0; } diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index c571fdecf7..5e8fdd0ff1 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -662,10 +662,9 @@ qemuFirmwareInterfaceFormat(virJSONValuePtr doc, if (virJSONValueObjectAppend(doc, "interface-types", - interfacesJSON) < 0) + &interfacesJSON) < 0) return -1; - interfacesJSON =3D NULL; return 0; } @@ -706,18 +705,15 @@ qemuFirmwareMappingFlashFormat(virJSONValuePtr mappin= g, if (virJSONValueObjectAppend(mapping, "executable", - executable) < 0) + &executable) < 0) return -1; - executable =3D NULL; if (virJSONValueObjectAppend(mapping, "nvram-template", - nvram_template) < 0) + &nvram_template) < 0) return -1; - nvram_template =3D NULL; - return 0; } @@ -778,10 +774,9 @@ qemuFirmwareMappingFormat(virJSONValuePtr doc, break; } - if (virJSONValueObjectAppend(doc, "mapping", mapping) < 0) + if (virJSONValueObjectAppend(doc, "mapping", &mapping) < 0) return -1; - mapping =3D NULL; return 0; } @@ -814,21 +809,18 @@ qemuFirmwareTargetFormat(virJSONValuePtr doc, return -1; } - if (virJSONValueObjectAppend(target, "machines", machines) < 0) + if (virJSONValueObjectAppend(target, "machines", &machines) < 0) return -1; - machines =3D NULL; - if (virJSONValueArrayAppend(targetsJSON, target) < 0) return -1; target =3D NULL; } - if (virJSONValueObjectAppend(doc, "targets", targetsJSON) < 0) + if (virJSONValueObjectAppend(doc, "targets", &targetsJSON) < 0) return -1; - targetsJSON =3D NULL; return 0; } @@ -850,10 +842,9 @@ qemuFirmwareFeatureFormat(virJSONValuePtr doc, if (virJSONValueObjectAppend(doc, "features", - featuresJSON) < 0) + &featuresJSON) < 0) return -1; - featuresJSON =3D NULL; return 0; } diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index f8c78d9093..924e03b4da 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -4554,9 +4554,8 @@ qemuMonitorJSONAddDeviceArgs(qemuMonitorPtr mon, if (!(cmd =3D qemuMonitorJSONMakeCommand("device_add", NULL))) goto cleanup; - if (virJSONValueObjectAppend(cmd, "arguments", args) < 0) + if (virJSONValueObjectAppend(cmd, "arguments", &args) < 0) goto cleanup; - args =3D NULL; /* obj owns reference to args now */ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -5572,9 +5571,8 @@ int qemuMonitorJSONSetBlockIoThrottle(qemuMonitorPtr = mon, NULL) < 0) goto cleanup; - if (virJSONValueObjectAppend(cmd, "arguments", args) < 0) + if (virJSONValueObjectAppend(cmd, "arguments", &args) < 0) goto cleanup; - args =3D NULL; /* obj owns reference to args now */ if (qemuMonitorJSONCommand(mon, cmd, &result) < 0) goto cleanup; @@ -5989,7 +5987,7 @@ qemuMonitorJSONMakeCPUModel(virCPUDefPtr cpu, goto error; } - if (virJSONValueObjectAppend(model, "props", props) < 0) + if (virJSONValueObjectAppend(model, "props", &props) < 0) goto error; } @@ -7470,9 +7468,8 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, addr =3D qemuMonitorJSONBuildInetSocketAddress(chr->data.tcp.host, chr->data.tcp.service= ); if (!addr || - virJSONValueObjectAppend(data, "addr", addr) < 0) + virJSONValueObjectAppend(data, "addr", &addr) < 0) goto cleanup; - addr =3D NULL; telnet =3D chr->data.tcp.protocol =3D=3D VIR_DOMAIN_CHR_TCP_PROTOC= OL_TELNET; @@ -7503,7 +7500,7 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, addr =3D qemuMonitorJSONBuildInetSocketAddress(host, chr->data.udp.connect= Service); if (!addr || - virJSONValueObjectAppend(data, "remote", addr) < 0) + virJSONValueObjectAppend(data, "remote", &addr) < 0) goto cleanup; host =3D chr->data.udp.bindHost; @@ -7515,10 +7512,9 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrI= D, port =3D ""; addr =3D qemuMonitorJSONBuildInetSocketAddress(host, port); if (!addr || - virJSONValueObjectAppend(data, "local", addr) < 0) + virJSONValueObjectAppend(data, "local", &addr) < 0) goto cleanup; } - addr =3D NULL; break; case VIR_DOMAIN_CHR_TYPE_UNIX: @@ -7526,9 +7522,8 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, addr =3D qemuMonitorJSONBuildUnixSocketAddress(chr->data.nix.path); if (!addr || - virJSONValueObjectAppend(data, "addr", addr) < 0) + virJSONValueObjectAppend(data, "addr", &addr) < 0) goto cleanup; - addr =3D NULL; if (chr->data.nix.listen && virJSONValueObjectAppendBoolean(data, "wait", false) < 0) @@ -7574,9 +7569,8 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, goto cleanup; if (virJSONValueObjectAppendString(backend, "type", backend_type) < 0 = || - virJSONValueObjectAppend(backend, "data", data) < 0) + virJSONValueObjectAppend(backend, "data", &data) < 0) goto cleanup; - data =3D NULL; if (!(ret =3D qemuMonitorJSONMakeCommand("chardev-add", "s:id", chrID, diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index 6132615093..327540c4b4 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -404,16 +404,14 @@ virNetDaemonPreExecRestart(virNetDaemonPtr dmn) if (!srvJSON) goto error; - if (virJSONValueObjectAppend(srvObj, srvArray[i].key, srvJSON) < 0) + if (virJSONValueObjectAppend(srvObj, srvArray[i].key, &srvJSON) < = 0) goto error; - srvJSON =3D NULL; } virObjectUnlock(dmn); - if (virJSONValueObjectAppend(object, "servers", srvObj) < 0) + if (virJSONValueObjectAppend(object, "servers", &srvObj) < 0) return NULL; - srvObj =3D NULL; return g_steal_pointer(&object); diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index ee402e8ea0..c2650ade09 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -590,9 +590,8 @@ virJSONValuePtr virNetServerPreExecRestart(virNetServer= Ptr srv) child =3D NULL; } - if (virJSONValueObjectAppend(object, "services", services) < 0) + if (virJSONValueObjectAppend(object, "services", &services) < 0) goto error; - services =3D NULL; for (i =3D 0; i < srv->nclients; i++) { g_autoptr(virJSONValue) child =3D NULL; @@ -604,9 +603,8 @@ virJSONValuePtr virNetServerPreExecRestart(virNetServer= Ptr srv) child =3D NULL; } - if (virJSONValueObjectAppend(object, "clients", clients) < 0) + if (virJSONValueObjectAppend(object, "clients", &clients) < 0) goto error; - clients =3D NULL; virObjectUnlock(srv); diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c index 0789ad9154..2bb3443287 100644 --- a/src/rpc/virnetserverclient.c +++ b/src/rpc/virnetserverclient.c @@ -610,16 +610,14 @@ virJSONValuePtr virNetServerClientPreExecRestart(virN= etServerClientPtr client) if (!(sock =3D virNetSocketPreExecRestart(client->sock))) goto error; - if (virJSONValueObjectAppend(object, "sock", sock) < 0) + if (virJSONValueObjectAppend(object, "sock", &sock) < 0) goto error; - sock =3D NULL; if (!(priv =3D client->privateDataPreExecRestart(client, client->priva= teData))) goto error; - if (virJSONValueObjectAppend(object, "privateData", priv) < 0) + if (virJSONValueObjectAppend(object, "privateData", &priv) < 0) goto error; - priv =3D NULL; virObjectUnlock(client); return g_steal_pointer(&object); diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c index a72277226a..fece6305e8 100644 --- a/src/rpc/virnetserverservice.c +++ b/src/rpc/virnetserverservice.c @@ -357,9 +357,8 @@ virJSONValuePtr virNetServerServicePreExecRestart(virNe= tServerServicePtr svc) child =3D NULL; } - if (virJSONValueObjectAppend(object, "socks", socks) < 0) + if (virJSONValueObjectAppend(object, "socks", &socks) < 0) return NULL; - socks =3D NULL; return g_steal_pointer(&object); } diff --git a/src/util/virjson.c b/src/util/virjson.c index 7b52525797..5b3aa49a7f 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -298,7 +298,7 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj, return -1; } - if ((rc =3D virJSONValueObjectAppend(obj, key, *val)) =3D=3D 0) + if ((rc =3D virJSONValueObjectAppend(obj, key, val)) =3D=3D 0) *val =3D NULL; } break; @@ -320,9 +320,8 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj, if (!(jsonMap =3D virJSONValueNewArrayFromBitmap(map))) return -1; - if ((rc =3D virJSONValueObjectAppend(obj, key, jsonMap)) < 0) + if ((rc =3D virJSONValueObjectAppend(obj, key, &jsonMap)) < 0) return -1; - jsonMap =3D NULL; } break; default: @@ -616,9 +615,9 @@ virJSONValueObjectInsert(virJSONValuePtr object, int virJSONValueObjectAppend(virJSONValuePtr object, const char *key, - virJSONValuePtr value) + virJSONValuePtr *value) { - return virJSONValueObjectInsert(object, key, &value, false); + return virJSONValueObjectInsert(object, key, value, false); } @@ -679,9 +678,8 @@ virJSONValueObjectAppendNumberInt(virJSONValuePtr objec= t, { g_autoptr(virJSONValue) jvalue =3D virJSONValueNewNumberInt(number); - if (virJSONValueObjectAppend(object, key, jvalue) < 0) + if (virJSONValueObjectAppend(object, key, &jvalue) < 0) return -1; - jvalue =3D NULL; return 0; } @@ -694,9 +692,8 @@ virJSONValueObjectAppendNumberUint(virJSONValuePtr obje= ct, { g_autoptr(virJSONValue) jvalue =3D virJSONValueNewNumberUint(number); - if (virJSONValueObjectAppend(object, key, jvalue) < 0) + if (virJSONValueObjectAppend(object, key, &jvalue) < 0) return -1; - jvalue =3D NULL; return 0; } @@ -709,9 +706,8 @@ virJSONValueObjectAppendNumberLong(virJSONValuePtr obje= ct, { g_autoptr(virJSONValue) jvalue =3D virJSONValueNewNumberLong(number); - if (virJSONValueObjectAppend(object, key, jvalue) < 0) + if (virJSONValueObjectAppend(object, key, &jvalue) < 0) return -1; - jvalue =3D NULL; return 0; } @@ -724,9 +720,8 @@ virJSONValueObjectAppendNumberUlong(virJSONValuePtr obj= ect, { g_autoptr(virJSONValue) jvalue =3D virJSONValueNewNumberUlong(number); - if (virJSONValueObjectAppend(object, key, jvalue) < 0) + if (virJSONValueObjectAppend(object, key, &jvalue) < 0) return -1; - jvalue =3D NULL; return 0; } @@ -743,9 +738,8 @@ virJSONValueObjectAppendNumberDouble(virJSONValuePtr ob= ject, if (!jvalue) return -1; - if (virJSONValueObjectAppend(object, key, jvalue) < 0) + if (virJSONValueObjectAppend(object, key, &jvalue) < 0) return -1; - jvalue =3D NULL; return 0; } @@ -758,9 +752,8 @@ virJSONValueObjectAppendBoolean(virJSONValuePtr object, { g_autoptr(virJSONValue) jvalue =3D virJSONValueNewBoolean(boolean_); - if (virJSONValueObjectAppend(object, key, jvalue) < 0) + if (virJSONValueObjectAppend(object, key, &jvalue) < 0) return -1; - jvalue =3D NULL; return 0; } @@ -772,9 +765,8 @@ virJSONValueObjectAppendNull(virJSONValuePtr object, { g_autoptr(virJSONValue) jvalue =3D virJSONValueNewNull(); - if (virJSONValueObjectAppend(object, key, jvalue) < 0) + if (virJSONValueObjectAppend(object, key, &jvalue) < 0) return -1; - jvalue =3D NULL; return 0; } @@ -1583,7 +1575,7 @@ virJSONParserInsertValue(virJSONParserPtr parser, if (virJSONValueObjectAppend(state->value, state->key, - value) < 0) + &value) < 0) return -1; VIR_FREE(state->key); @@ -2093,7 +2085,7 @@ virJSONValueObjectDeflattenWorker(const char *key, return -1; } - if (virJSONValueObjectAppend(retobj, key, newval) < 0) + if (virJSONValueObjectAppend(retobj, key, &newval) < 0) return -1; newval =3D NULL; @@ -2111,9 +2103,10 @@ virJSONValueObjectDeflattenWorker(const char *key, } if (!(existobj =3D virJSONValueObjectGet(retobj, tokens[0]))) { - existobj =3D virJSONValueNewObject(); + virJSONValuePtr newobj =3D virJSONValueNewObject(); + existobj =3D newobj; - if (virJSONValueObjectAppend(retobj, tokens[0], existobj) < 0) + if (virJSONValueObjectAppend(retobj, tokens[0], &newobj) < 0) return -1; } else { diff --git a/src/util/virjson.h b/src/util/virjson.h index 4dc7ed1a2d..ca99ae3b70 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -69,7 +69,9 @@ virJSONValuePtr virJSONValueNewArray(void); virJSONValuePtr virJSONValueNewObject(void); virJSONValuePtr virJSONValueNewArrayFromBitmap(virBitmapPtr bitmap); -int virJSONValueObjectAppend(virJSONValuePtr object, const char *key, virJ= SONValuePtr value); +int virJSONValueObjectAppend(virJSONValuePtr object, + const char *key, + virJSONValuePtr *value); int virJSONValueArrayAppend(virJSONValuePtr object, virJSONValuePtr value); int virJSONValueArrayConcat(virJSONValuePtr a, virJSONValuePtr c); diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c index 1b6b51b649..9ba6e83251 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -460,9 +460,8 @@ virJSONValuePtr virLockSpacePreExecRestart(virLockSpace= Ptr lockspace) owner =3D NULL; } - if (virJSONValueObjectAppend(child, "owners", owners) < 0) + if (virJSONValueObjectAppend(child, "owners", &owners) < 0) goto error; - owners =3D NULL; if (virJSONValueArrayAppend(resources, child) < 0) goto error; @@ -471,9 +470,8 @@ virJSONValuePtr virLockSpacePreExecRestart(virLockSpace= Ptr lockspace) tmp++; } - if (virJSONValueObjectAppend(object, "resources", resources) < 0) + if (virJSONValueObjectAppend(object, "resources", &resources) < 0) goto error; - resources =3D NULL; virMutexUnlock(&lockspace->lock); return object; diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c index 0d458d7b7b..521ab89b5b 100644 --- a/src/util/virmacmap.c +++ b/src/util/virmacmap.c @@ -224,9 +224,8 @@ virMACMapHashDumper(void *payload, } if (virJSONValueObjectAppendString(obj, "domain", name) < 0 || - virJSONValueObjectAppend(obj, "macs", arr) < 0) + virJSONValueObjectAppend(obj, "macs", &arr) < 0) return -1; - arr =3D NULL; if (virJSONValueArrayAppend(data, obj) < 0) return -1; --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 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=1613152696; cv=none; d=zohomail.com; s=zohoarc; b=Q0tAA0L3nfCOzK+t/eQbK3eHHLDLOwgPIlPLzhQk7ekGjsbbjucsMrF0k5nplboKroGryCIYZ9JskrT9xEF3x/E9mrGUXSl/o6KnlWQy3L5Dk8P1U095tIB+qcR4APBZ86zuXzW4F7W0tVQYT2p9+vBQRyg2LzQZfGgEQjrNONk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152696; 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=z4GGwhxTnowYDZWicZic4mfMSDgpwvPZIeaSDd8svTw=; b=QELplDehgFiiXKjiyuD/BhcgPy47fAAB0oOt1NgP71CxgUCTSZwmy+rouc+pgxfdmnZiYlgyZR8GJqq2jJUDybkerNtnTpBgxYZ+9rVOSg4u5NgquTehB8nokxaZ6zBjY5UP7y6DZKr6hRhVLkkiOMSr0yHAH3ZQ3BurgIDImXI= 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 161315269578585.67965086541255; Fri, 12 Feb 2021 09:58:15 -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-472--AyGP0JKPrWFvhU39d1Lhw-1; Fri, 12 Feb 2021 12:57:30 -0500 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 DAC49BBEFC; Fri, 12 Feb 2021 17:56:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B889A5C3E0; Fri, 12 Feb 2021 17:56:48 +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 7EA9D58074; Fri, 12 Feb 2021 17:56:48 +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 11CHufWa010940 for ; Fri, 12 Feb 2021 12:56:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id BD03D5C3E0; Fri, 12 Feb 2021 17:56:41 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 207725C23D for ; Fri, 12 Feb 2021 17:56:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152692; 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=z4GGwhxTnowYDZWicZic4mfMSDgpwvPZIeaSDd8svTw=; b=gBu5TfDl2UmCV+6adiR07Gufni33xPNY+B5GjQKX8BSA+Lx70mt3YPndppA0sNLnNpRWDN e7fr44vzY8BLXxfQ3TWeXS0ZN3raWBxQ120cjy8U0edT4acy0ZWJNo8srZSJyMxHkcGweK /W8sizaJ8LenCvLQp8pIsZbyxQG7jZo= X-MC-Unique: -AyGP0JKPrWFvhU39d1Lhw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 17/25] qemuAgentMakeStringsArray: Refactor cleanup Date: Fri, 12 Feb 2021 18:55:30 +0100 Message-Id: <90a2c431a7763d1ec421e7ad67268c72996a54c0.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.16 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" Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_agent.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 4712aeb529..d6816ef9de 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1175,23 +1175,17 @@ static virJSONValuePtr qemuAgentMakeStringsArray(const char **strings, unsigned int len) { size_t i; - virJSONValuePtr ret =3D virJSONValueNewArray(), str; + g_autoptr(virJSONValue) ret =3D virJSONValueNewArray(); for (i =3D 0; i < len; i++) { - str =3D virJSONValueNewString(strings[i]); - if (!str) - goto error; + g_autoptr(virJSONValue) str =3D virJSONValueNewString(strings[i]); - if (virJSONValueArrayAppend(ret, str) < 0) { - virJSONValueFree(str); - goto error; - } + if (virJSONValueArrayAppend(ret, str) < 0) + return NULL; + str =3D NULL; } - return ret; - error: - virJSONValueFree(ret); - return NULL; + return g_steal_pointer(&ret); } void qemuAgentNotifyEvent(qemuAgentPtr agent, --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 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=1613152649; cv=none; d=zohomail.com; s=zohoarc; b=ctSuVfAcA4W59Uvgmvy84sABvx6Irvs3JL/kE0hh0aM89/yULzB9IVzxqnwFJm09A5M0+LGEPfUpXXeJU5e4GC2oZwycSpEzXuKl7k3qsrl0uYWc73J8qFQMVBlWndz/3JULz0STTrCd7AUMZfaEJpddL/C6FFZU2CsX31Ofcac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152649; 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=Vg63KNivJkr/TAG9r3S3pnhpqHUB4h9HXuEsexSpy3U=; b=X4TfuSla59uMc5DaWPc/rPwOfw7eyYkYbJbMX5A5GZEn3Ef+Ev80j1veERl/JwrI0EhSXwMKLDjoVy0PZPTr4fF7+rBILcK17cqc5MnpGHgU3eY+MwU4m2Al2APerj08qJcwPy2OmcZLyeAuVfOqKMgWXTrNogVyL92kdn140V8= 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 1613152649310895.2594049047201; Fri, 12 Feb 2021 09:57:29 -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-405-Q-BElqEjOIOFpo-_evTUWA-1; Fri, 12 Feb 2021 12:57:24 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B331A187CE4B; Fri, 12 Feb 2021 17:56:51 +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 92D2560C17; Fri, 12 Feb 2021 17:56:51 +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 5CB7B18095CC; Fri, 12 Feb 2021 17:56:51 +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 11CHug5n010950 for ; Fri, 12 Feb 2021 12:56:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id D8E005C23D; Fri, 12 Feb 2021 17:56:42 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 379E85C3FD for ; Fri, 12 Feb 2021 17:56:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152647; 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=Vg63KNivJkr/TAG9r3S3pnhpqHUB4h9HXuEsexSpy3U=; b=Z2v89r41qKpetRxUZYSETT2bNIwux8G2E8nNMdZCv8iXuHu8wLTzc8KuNS45DyIDXKn6ii GuBRsUM/yFSnkOQ0YNjYiPexYcggGFXF8kTM+sBb2nN+/SXUGV6/H2lEPIHSC5eyK2yW/E bi7/gxPnpdw8jaKthYfkVlTvOwGAHLA= X-MC-Unique: Q-BElqEjOIOFpo-_evTUWA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 18/25] virMACMapHashDumper: Refactor array addition Date: Fri, 12 Feb 2021 18:55:31 +0100 Message-Id: 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.12 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" Use automatic memory freeing and don't check return value of virJSONValueNewString as it can't fail. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virmacmap.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c index 521ab89b5b..12df325933 100644 --- a/src/util/virmacmap.c +++ b/src/util/virmacmap.c @@ -214,13 +214,11 @@ virMACMapHashDumper(void *payload, GSList *next; for (next =3D macs; next; next =3D next->next) { - virJSONValuePtr m =3D virJSONValueNewString((const char *) next->d= ata); + g_autoptr(virJSONValue) m =3D virJSONValueNewString((const char *)= next->data); - if (!m || - virJSONValueArrayAppend(arr, m) < 0) { - virJSONValueFree(m); + if (virJSONValueArrayAppend(arr, m) < 0) return -1; - } + m =3D NULL; } if (virJSONValueObjectAppendString(obj, "domain", name) < 0 || --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 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=1613152689; cv=none; d=zohomail.com; s=zohoarc; b=kKKSTdosyPy7MzjXZywllot6P1ae8GZ10hq9c34SeJYpDhYAERE7ymb1PNiVVl5GLhAWVwFVSawxofFbIjJkQvOAtau6jPcYt7p3YT9RnegdR0YLngGsaS75neKcXnr/IkyWSoJ2z7sjpBgGbBC79rBFgjYLMINkO6+Hix8Jlgg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152689; 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=TYkMZ0XrZr3J5hFKqVXYCPBYMFgXaGftviFa/dcBGxM=; b=LpOVPzgRB9Vx62Sk/vehaVxmeiIVD3EUr1Jr3cr0uckG5nep6tD8IrJ6qmXqk91xoASrAs1NwgHm2PETwlC+5bMFUIj1ILLuqu+79vdZyyLBUPkGA33KWTLa/XEk4LpaUU2EI+ynpohGrGWp/UAJqcACN7nmazdYpl08F7I0/jA= 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 1613152688915324.79757864162445; Fri, 12 Feb 2021 09:58:08 -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-409-A4Vb5R7xPtuXiCMz2Io6PA-1; Fri, 12 Feb 2021 12:57:24 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ABA8AC7405; Fri, 12 Feb 2021 17:56:54 +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 7CFCF47; Fri, 12 Feb 2021 17:56:54 +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 3C58118095CE; Fri, 12 Feb 2021 17:56:54 +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 11CHuhTv010969 for ; Fri, 12 Feb 2021 12:56:43 -0500 Received: by smtp.corp.redhat.com (Postfix) id EC42F5C3E0; Fri, 12 Feb 2021 17:56:43 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 514505C23D for ; Fri, 12 Feb 2021 17:56:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152683; 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=TYkMZ0XrZr3J5hFKqVXYCPBYMFgXaGftviFa/dcBGxM=; b=KZ6LouH1EeeYoP6mqTHflOKERvpnTbCH9KyAR4OFhmeOiEbk9b9tT9nXNmAiWSVlOWPSjy 1E9qAzcRFXFA98HrMOgBNF2Oxro0XLvpf3ntkWgRqMPMuHKHU5NoFg1LOUD4gbX6NNWdN+ LfT3wLLuZiCfUBWsWTuysgBjr6w3Mlw= X-MC-Unique: A4Vb5R7xPtuXiCMz2Io6PA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 19/25] testQEMUSchemaValidateObjectMergeVariantMember: Fix theoretical leak Date: Fri, 12 Feb 2021 18:55:32 +0100 Message-Id: <181300cfafc458c8aac8af3f323ce929c88ed19b.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.84 on 10.5.11.23 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" Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- tests/testutilsqemuschema.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c index 101687e657..4bb303a427 100644 --- a/tests/testutilsqemuschema.c +++ b/tests/testutilsqemuschema.c @@ -163,13 +163,14 @@ testQEMUSchemaValidateObjectMergeVariantMember(size_t= pos G_GNUC_UNUSED, void *opaque) { virJSONValuePtr array =3D opaque; - virJSONValuePtr copy; + g_autoptr(virJSONValue) copy =3D NULL; if (!(copy =3D virJSONValueCopy(item))) return -1; if (virJSONValueArrayAppend(array, copy) < 0) return -1; + copy =3D NULL; return 1; } --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1613152691; cv=none; d=zohomail.com; s=zohoarc; b=FuISJITXZv7A9GF1K0glGlgu2Z2ws2jn+uvS3Sk8ymoURifQAPKA+W9kykYiGzQDO6LeW3ITTW7Pwa+19zkgDPm96Xh8yL8PA0JTBqNTg3O5+9AcD2z+jpEu7QrZdAGTmHufMrqNLUK2FHDRpoqqlIMd9QKESPoAKb8GZaV/1+Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152691; 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=0gLacWkBDvsAvULNGYNfOIYhy13n5xEPQvxCjzHEUqw=; b=kX2dn5Cb5xUSJUguvEqTh1uzwUmI1a/HkqIsr7PiWI+TaR3VZZzQJT213EIPr1yWAdQxG42qRtFrPCXrIDg1VBJQBslAMFKXJ/DMnecLZH6GecJ9kLO8zMltdx7AA2zyPdP4azXT3MYzm9ge2qy8/I0y7GbgssZJY9gH4aSQteo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1613152690730783.7463571761234; 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-293-BFQLcbexNnO65mFW_0etRg-1; Fri, 12 Feb 2021 12:57:26 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 48BCF10513CC; Fri, 12 Feb 2021 17:56:48 +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 252315D6AB; Fri, 12 Feb 2021 17:56:48 +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 DC45618095CC; Fri, 12 Feb 2021 17:56:47 +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 11CHuj0e010985 for ; Fri, 12 Feb 2021 12:56:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id 774275C3E0; Fri, 12 Feb 2021 17:56:45 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79ED05C23D for ; Fri, 12 Feb 2021 17:56:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152686; 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=0gLacWkBDvsAvULNGYNfOIYhy13n5xEPQvxCjzHEUqw=; b=HWZKFu59LHBKR3WRZ2fYiymYRoaImB2vv17h7NBrnPPY4muRqrEoZuaLBQZeqX7jQ/rLaw kZQ3qHzcIFTF9Z+IHraYsM/NGHMYPFcFFVSyNpQy3vPRdTHvA/0gwPawZgY8ZYg4ULuq0n nUOAHlyoCXhEQ/M33R4V/05oftRRdoM= X-MC-Unique: BFQLcbexNnO65mFW_0etRg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 20/25] virJSONValueArrayAppend: Clear pointer when taking ownership of passed value Date: Fri, 12 Feb 2021 18:55:33 +0100 Message-Id: <92aac862492454e10ea3506b0d307bdcc6199b07.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.15 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 parent array takes ownership of the inserted value once all checks pass. Don't make the callers second-guess when that happens and modify the function to take a double pointer so that it can be cleared once the ownership is taken. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/locking/lock_daemon.c | 3 +-- src/logging/log_handler.c | 3 +-- src/network/leaseshelper.c | 3 +-- src/node_device/node_device_driver.c | 2 +- src/qemu/qemu_agent.c | 7 ++----- src/qemu/qemu_block.c | 16 ++++------------ src/qemu/qemu_command.c | 3 +-- src/qemu/qemu_firmware.c | 4 +--- src/qemu/qemu_migration_params.c | 4 +--- src/qemu/qemu_monitor_json.c | 11 +++-------- src/rpc/virnetserver.c | 6 ++---- src/rpc/virnetserverservice.c | 3 +-- src/util/virjson.c | 12 +++++------- src/util/virjson.h | 3 ++- src/util/virlease.c | 2 +- src/util/virlockspace.c | 6 ++---- src/util/virmacmap.c | 6 ++---- tests/testutilsqemuschema.c | 3 +-- 18 files changed, 32 insertions(+), 65 deletions(-) diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 26905a462b..d68c61b099 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -728,9 +728,8 @@ virLockDaemonPreExecRestart(const char *state_file, if (!(child =3D virLockSpacePreExecRestart(lockspace))) return -1; - if (virJSONValueArrayAppend(lockspaces, child) < 0) + if (virJSONValueArrayAppend(lockspaces, &child) < 0) return -1; - child =3D NULL; tmp++; } diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c index d649c4d132..9e027c7579 100644 --- a/src/logging/log_handler.c +++ b/src/logging/log_handler.c @@ -642,9 +642,8 @@ virLogHandlerPreExecRestart(virLogHandlerPtr handler) return NULL; } - if (virJSONValueArrayAppend(files, file) < 0) + if (virJSONValueArrayAppend(files, &file) < 0) return NULL; - file =3D NULL; } if (virJSONValueObjectAppend(ret, "files", &files) < 0) diff --git a/src/network/leaseshelper.c b/src/network/leaseshelper.c index c20e63efa9..ca2c640672 100644 --- a/src/network/leaseshelper.c +++ b/src/network/leaseshelper.c @@ -226,12 +226,11 @@ main(int argc, char **argv) case VIR_LEASE_ACTION_OLD: case VIR_LEASE_ACTION_ADD: - if (lease_new && virJSONValueArrayAppend(leases_array_new, lease_n= ew) < 0) { + if (lease_new && virJSONValueArrayAppend(leases_array_new, &lease_= new) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to create json")); goto cleanup; } - lease_new =3D NULL; G_GNUC_FALLTHROUGH; case VIR_LEASE_ACTION_DEL: diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index d946e64ad6..543e5bb90a 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -606,7 +606,7 @@ nodeDeviceDefToMdevctlConfig(virNodeDeviceDefPtr def, c= har **buf) if (virJSONValueObjectAppendString(jsonattr, attr->name, attr-= >value) < 0) return -1; - if (virJSONValueArrayAppend(attributes, g_steal_pointer(&jsona= ttr)) < 0) + if (virJSONValueArrayAppend(attributes, &jsonattr) < 0) return -1; } diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index d6816ef9de..9aec0fdb4b 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1180,9 +1180,8 @@ qemuAgentMakeStringsArray(const char **strings, unsig= ned int len) for (i =3D 0; i < len; i++) { g_autoptr(virJSONValue) str =3D virJSONValueNewString(strings[i]); - if (virJSONValueArrayAppend(ret, str) < 0) + if (virJSONValueArrayAppend(ret, &str) < 0) return NULL; - str =3D NULL; } return g_steal_pointer(&ret); @@ -1514,10 +1513,8 @@ qemuAgentSetVCPUsCommand(qemuAgentPtr agent, if (virJSONValueObjectAppendBoolean(cpu, "online", in->online) < 0) goto cleanup; - if (virJSONValueArrayAppend(cpus, cpu) < 0) + if (virJSONValueArrayAppend(cpus, &cpu) < 0) goto cleanup; - - cpu =3D NULL; } if (*nmodified =3D=3D 0) { diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 1df51ba97b..94cbb1d12e 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -534,10 +534,8 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virS= torageSourcePtr src, if (!(server =3D qemuBlockStorageSourceBuildJSONSocketAddress(host= , legacy))) return NULL; - if (virJSONValueArrayAppend(servers, server) < 0) + if (virJSONValueArrayAppend(servers, &server) < 0) return NULL; - - server =3D NULL; } return g_steal_pointer(&servers); @@ -622,10 +620,8 @@ qemuBlockStorageSourceBuildHostsJSONInetSocketAddress(= virStorageSourcePtr src) if (!(server =3D qemuBlockStorageSourceBuildJSONInetSocketAddress(= host))) return NULL; - if (virJSONValueArrayAppend(servers, server) < 0) + if (virJSONValueArrayAppend(servers, &server) < 0) return NULL; - - server =3D NULL; } return g_steal_pointer(&servers); @@ -912,16 +908,12 @@ qemuBlockStorageSourceGetRBDProps(virStorageSourcePtr= src, authmodes =3D virJSONValueNewArray(); if (!(mode =3D virJSONValueNewString("cephx")) || - virJSONValueArrayAppend(authmodes, mode) < 0) + virJSONValueArrayAppend(authmodes, &mode) < 0) return NULL; - mode =3D NULL; - if (!(mode =3D virJSONValueNewString("none")) || - virJSONValueArrayAppend(authmodes, mode) < 0) + virJSONValueArrayAppend(authmodes, &mode) < 0) return NULL; - - mode =3D NULL; } if (virJSONValueObjectCreate(&ret, diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d27d5eb55b..3037d1d5a5 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -10200,9 +10200,8 @@ qemuBuildChannelGuestfwdNetdevProps(virDomainChrDef= Ptr chr) chr->info.alias) < 0) return NULL; - if (virJSONValueArrayAppend(guestfwdarr, guestfwdstrobj) < 0) + if (virJSONValueArrayAppend(guestfwdarr, &guestfwdstrobj) < 0) return NULL; - guestfwdstrobj =3D NULL; if (virJSONValueObjectCreate(&ret, "s:type", "user", diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index 5e8fdd0ff1..d3198e2d45 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -812,10 +812,8 @@ qemuFirmwareTargetFormat(virJSONValuePtr doc, if (virJSONValueObjectAppend(target, "machines", &machines) < 0) return -1; - if (virJSONValueArrayAppend(targetsJSON, target) < 0) + if (virJSONValueArrayAppend(targetsJSON, &target) < 0) return -1; - - target =3D NULL; } if (virJSONValueObjectAppend(doc, "targets", &targetsJSON) < 0) diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_par= ams.c index 510dad783a..302a9933e1 100644 --- a/src/qemu/qemu_migration_params.c +++ b/src/qemu/qemu_migration_params.c @@ -770,10 +770,8 @@ qemuMigrationCapsToJSON(virBitmapPtr caps, NULL) < 0) return NULL; - if (virJSONValueArrayAppend(json, cap) < 0) + if (virJSONValueArrayAppend(json, &cap) < 0) return NULL; - - cap =3D NULL; } return g_steal_pointer(&json); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 924e03b4da..94365c775b 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -525,10 +525,9 @@ qemuMonitorJSONTransactionAdd(virJSONValuePtr actions, "A:data", &data, NULL) < 0) goto cleanup; - if (virJSONValueArrayAppend(actions, entry) < 0) + if (virJSONValueArrayAppend(actions, &entry) < 0) goto cleanup; - entry =3D NULL; ret =3D 0; cleanup: @@ -4976,11 +4975,8 @@ int qemuMonitorJSONSendKey(qemuMonitorPtr mon, if (virJSONValueObjectAppendNumberInt(key, "data", keycodes[i]) < = 0) goto cleanup; - if (virJSONValueArrayAppend(keys, key) < 0) + if (virJSONValueArrayAppend(keys, &key) < 0) goto cleanup; - - key =3D NULL; - } cmd =3D qemuMonitorJSONMakeCommand("send-key", @@ -9289,10 +9285,9 @@ qemuMonitorJSONTransactionBitmapMergeSourceAddBitmap= (virJSONValuePtr sources, NULL) < 0) return -1; - if (virJSONValueArrayAppend(sources, sourceobj) < 0) + if (virJSONValueArrayAppend(sources, &sourceobj) < 0) return -1; - sourceobj =3D NULL; return 0; } diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index c2650ade09..30faa0190b 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -585,9 +585,8 @@ virJSONValuePtr virNetServerPreExecRestart(virNetServer= Ptr srv) if (!(child =3D virNetServerServicePreExecRestart(srv->services[i]= ))) goto error; - if (virJSONValueArrayAppend(services, child) < 0) + if (virJSONValueArrayAppend(services, &child) < 0) goto error; - child =3D NULL; } if (virJSONValueObjectAppend(object, "services", &services) < 0) @@ -598,9 +597,8 @@ virJSONValuePtr virNetServerPreExecRestart(virNetServer= Ptr srv) if (!(child =3D virNetServerClientPreExecRestart(srv->clients[i]))) goto error; - if (virJSONValueArrayAppend(clients, child) < 0) + if (virJSONValueArrayAppend(clients, &child) < 0) goto error; - child =3D NULL; } if (virJSONValueObjectAppend(object, "clients", &clients) < 0) diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c index fece6305e8..ce2dd4f28b 100644 --- a/src/rpc/virnetserverservice.c +++ b/src/rpc/virnetserverservice.c @@ -352,9 +352,8 @@ virJSONValuePtr virNetServerServicePreExecRestart(virNe= tServerServicePtr svc) if (!(child =3D virNetSocketPreExecRestart(svc->socks[i]))) return NULL; - if (virJSONValueArrayAppend(socks, child) < 0) + if (virJSONValueArrayAppend(socks, &child) < 0) return NULL; - child =3D NULL; } if (virJSONValueObjectAppend(object, "socks", &socks) < 0) diff --git a/src/util/virjson.c b/src/util/virjson.c index 5b3aa49a7f..65215f03c5 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -774,7 +774,7 @@ virJSONValueObjectAppendNull(virJSONValuePtr object, int virJSONValueArrayAppend(virJSONValuePtr array, - virJSONValuePtr value) + virJSONValuePtr *value) { if (array->type !=3D VIR_JSON_TYPE_ARRAY) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("expecting JSON arr= ay")); @@ -785,7 +785,7 @@ virJSONValueArrayAppend(virJSONValuePtr array, array->data.array.nvalues + 1) < 0) return -1; - array->data.array.values[array->data.array.nvalues] =3D value; + array->data.array.values[array->data.array.nvalues] =3D g_steal_pointe= r(value); array->data.array.nvalues++; return 0; @@ -798,9 +798,8 @@ virJSONValueArrayAppendString(virJSONValuePtr object, { g_autoptr(virJSONValue) jvalue =3D virJSONValueNewString(value); - if (virJSONValueArrayAppend(object, jvalue) < 0) + if (virJSONValueArrayAppend(object, &jvalue) < 0) return -1; - jvalue =3D NULL; return 0; } @@ -1243,9 +1242,8 @@ virJSONValueNewArrayFromBitmap(virBitmapPtr bitmap) while ((pos =3D virBitmapNextSetBit(bitmap, pos)) > -1) { g_autoptr(virJSONValue) newelem =3D virJSONValueNewNumberLong(pos); - if (virJSONValueArrayAppend(ret, newelem) < 0) + if (virJSONValueArrayAppend(ret, &newelem) < 0) return NULL; - newelem =3D NULL; } return g_steal_pointer(&ret); @@ -1588,7 +1586,7 @@ virJSONParserInsertValue(virJSONParserPtr parser, } if (virJSONValueArrayAppend(state->value, - value) < 0) + &value) < 0) return -1; } break; diff --git a/src/util/virjson.h b/src/util/virjson.h index ca99ae3b70..c22bc1fb45 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -72,7 +72,8 @@ virJSONValuePtr virJSONValueNewArrayFromBitmap(virBitmapP= tr bitmap); int virJSONValueObjectAppend(virJSONValuePtr object, const char *key, virJSONValuePtr *value); -int virJSONValueArrayAppend(virJSONValuePtr object, virJSONValuePtr value); +int virJSONValueArrayAppend(virJSONValuePtr object, + virJSONValuePtr *value); int virJSONValueArrayConcat(virJSONValuePtr a, virJSONValuePtr c); diff --git a/src/util/virlease.c b/src/util/virlease.c index 3d68bb660c..59eaabd4d9 100644 --- a/src/util/virlease.c +++ b/src/util/virlease.c @@ -119,7 +119,7 @@ virLeaseReadCustomLeaseFile(virJSONValuePtr leases_arra= y_new, } /* Move old lease to new array */ - if (virJSONValueArrayAppend(leases_array_new, lease_tmp) < 0) { + if (virJSONValueArrayAppend(leases_array_new, &lease_tmp) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to create json")); return -1; diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c index 9ba6e83251..684a3320ed 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -455,17 +455,15 @@ virJSONValuePtr virLockSpacePreExecRestart(virLockSpa= cePtr lockspace) if (!owner) goto error; - if (virJSONValueArrayAppend(owners, owner) < 0) + if (virJSONValueArrayAppend(owners, &owner) < 0) goto error; - owner =3D NULL; } if (virJSONValueObjectAppend(child, "owners", &owners) < 0) goto error; - if (virJSONValueArrayAppend(resources, child) < 0) + if (virJSONValueArrayAppend(resources, &child) < 0) goto error; - child =3D NULL; tmp++; } diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c index 12df325933..bb14513c30 100644 --- a/src/util/virmacmap.c +++ b/src/util/virmacmap.c @@ -216,18 +216,16 @@ virMACMapHashDumper(void *payload, for (next =3D macs; next; next =3D next->next) { g_autoptr(virJSONValue) m =3D virJSONValueNewString((const char *)= next->data); - if (virJSONValueArrayAppend(arr, m) < 0) + if (virJSONValueArrayAppend(arr, &m) < 0) return -1; - m =3D NULL; } if (virJSONValueObjectAppendString(obj, "domain", name) < 0 || virJSONValueObjectAppend(obj, "macs", &arr) < 0) return -1; - if (virJSONValueArrayAppend(data, obj) < 0) + if (virJSONValueArrayAppend(data, &obj) < 0) return -1; - obj =3D NULL; return 0; } diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c index 4bb303a427..a842a219e2 100644 --- a/tests/testutilsqemuschema.c +++ b/tests/testutilsqemuschema.c @@ -168,9 +168,8 @@ testQEMUSchemaValidateObjectMergeVariantMember(size_t p= os G_GNUC_UNUSED, if (!(copy =3D virJSONValueCopy(item))) return -1; - if (virJSONValueArrayAppend(array, copy) < 0) + if (virJSONValueArrayAppend(array, ©) < 0) return -1; - copy =3D NULL; return 1; } --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 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=1613152652; cv=none; d=zohomail.com; s=zohoarc; b=kWLIGJObzgeLKvyPFFpOJnvWdc42Eo47B+hznhXdWIRnS2p/KEElLA/v9KSRcfZsX2X2wnMdTf7Ku9XE/2QqMCFP065qX9yjebrzgxfkaTF9+Azr476p/WuarhTTETwv5/DsD8pzC4EtWcLvWLyydtO0HAq/HtkpJvS90l5uqlc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152652; 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=bzi1pcB+tODVQdEXuu/fsAFdFq7hcM2ptyZBJcsFJKU=; b=Kch5yVyaLiocdxrEhG1/SKpFVFxcwcl21r7tKcwwbYC8nu8ojuHMFzGj9GzjUV6TdwOnFqMliOBPJW3jTfpAxol8/FHbnWi8ce5SePQux6Zb0KQvpgJ51BJ6Tul81jAHRK6hXtlTT+xkNKnRURGHis+qh3epKhwFBx7cCmY10ps= 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 1613152652982645.4697185178147; Fri, 12 Feb 2021 09:57:32 -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-425-fZ8QSTblMQ6GhP6kqhcKVw-1; Fri, 12 Feb 2021 12:57:27 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 90DC2102C809; Fri, 12 Feb 2021 17:56:57 +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 6E7E86B8E5; Fri, 12 Feb 2021 17:56:57 +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 3624618095CE; Fri, 12 Feb 2021 17:56:57 +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 11CHukhr011000 for ; Fri, 12 Feb 2021 12:56:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id C26345C3E0; Fri, 12 Feb 2021 17:56:46 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FDE418813 for ; Fri, 12 Feb 2021 17:56:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152651; 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=bzi1pcB+tODVQdEXuu/fsAFdFq7hcM2ptyZBJcsFJKU=; b=IqFeGAvHer5WTrSktGE9wvU6jD+bOXG0iL6WoLJBpNC+mSaFlSzue4hrNr4Fh9cA5/441h ++VQtzm3dk2R3zvIjBy+zWBKnHY8mzOLcaafXiImIGQdrKQ6MRk+f5FQDFC7UkdudCfAJR DsQow14xIxlh5ONhhfH1HLDfvTIAG8o= X-MC-Unique: fZ8QSTblMQ6GhP6kqhcKVw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 21/25] qemuMonitorJSONTransactionAdd: Refactor cleanup Date: Fri, 12 Feb 2021 18:55:34 +0100 Message-Id: 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.13 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" Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_monitor_json.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 94365c775b..76401c4d3c 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -510,31 +510,28 @@ qemuMonitorJSONTransactionAdd(virJSONValuePtr actions, const char *cmdname, ...) { - virJSONValuePtr entry =3D NULL; - virJSONValuePtr data =3D NULL; + g_autoptr(virJSONValue) entry =3D NULL; + g_autoptr(virJSONValue) data =3D NULL; va_list args; - int ret =3D -1; va_start(args, cmdname); - if (virJSONValueObjectCreateVArgs(&data, args) < 0) - goto cleanup; + if (virJSONValueObjectCreateVArgs(&data, args) < 0) { + va_end(args); + return -1; + } + + va_end(args); if (virJSONValueObjectCreate(&entry, "s:type", cmdname, "A:data", &data, NULL) < 0) - goto cleanup; + return -1; if (virJSONValueArrayAppend(actions, &entry) < 0) - goto cleanup; - - ret =3D 0; + return -1; - cleanup: - virJSONValueFree(entry); - virJSONValueFree(data); - va_end(args); - return ret; + return 0; } --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1613152762; cv=none; d=zohomail.com; s=zohoarc; b=Ntem+mrcwCOkuxfInVDP1BCYQNiLpoSAKJVp3Unf+Bq3Yw3PSIzf79szY2UUF2C6aQfv46iYvqinvNeBTEdIYOT5INNFQeyEDV08Ov7T4Y7hYCnmtgdpBOLybS8kqxWpdOB82YQ5/UWUGzN2XQphY+wNfeXx17mxIIgTZf26YrI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152762; 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=EzmKwViFir1+xA1aNkugiL8tQGimoqhC2eh9lRGNLrY=; b=expa8U89DBQYhmxPWaAWYfALTri9E2yxSpuQdMldsv456En9t96ZbrN6tZBapjPCZ6OYQPUXwKYflJZ9x5Nt/js9RicIFTsRdxNJcOV2EWm04rFVOVO+3VPhWg06m6zktxcY7Z7oZre5mh49a3gF2YzSSDXdzjGOfywrO23mIrY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1613152762188403.69465599364844; Fri, 12 Feb 2021 09:59:22 -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-601-ObVUPiDtMa21RAhO9qtdlg-1; Fri, 12 Feb 2021 12:57:35 -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 CCD4E879A0A; Fri, 12 Feb 2021 17:57:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AA4C95D9DB; Fri, 12 Feb 2021 17:57:00 +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 6E25858074; Fri, 12 Feb 2021 17:57:00 +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 11CHul5h011025 for ; Fri, 12 Feb 2021 12:56:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id D6F845C23D; Fri, 12 Feb 2021 17:56:47 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C11A5C8AD for ; Fri, 12 Feb 2021 17:56:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152757; 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=EzmKwViFir1+xA1aNkugiL8tQGimoqhC2eh9lRGNLrY=; b=TJY0yjw5oHeltUHu7mvZ8+GW9H7282huCjMpv80dddhbCOpgU6LCLjBhPXfstUVWc5W0hQ eU2Fdmz2icSGjBp4yuMga3zY6ptxQUQX+WTa6kklMswPyQB9Xi6HSqAakK2Rl5XARG0dc+ NubIeqoGosbqPZX0pQ5EZIa76Ynxu9c= X-MC-Unique: ObVUPiDtMa21RAhO9qtdlg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 22/25] qemuAgentSetVCPUsCommand: Refactor cleanup Date: Fri, 12 Feb 2021 18:55:35 +0100 Message-Id: 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" Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_agent.c | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 9aec0fdb4b..9a74b802b8 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1483,20 +1483,17 @@ qemuAgentSetVCPUsCommand(qemuAgentPtr agent, size_t ninfo, int *nmodified) { - int ret =3D -1; - virJSONValuePtr cmd =3D NULL; - virJSONValuePtr reply =3D NULL; - virJSONValuePtr cpus =3D NULL; - virJSONValuePtr cpu =3D NULL; + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; + g_autoptr(virJSONValue) cpus =3D virJSONValueNewArray(); size_t i; + int ret; *nmodified =3D 0; - /* create the key data array */ - cpus =3D virJSONValueNewArray(); - for (i =3D 0; i < ninfo; i++) { qemuAgentCPUInfoPtr in =3D &info[i]; + g_autoptr(virJSONValue) cpu =3D virJSONValueNewObject(); /* don't set state for cpus that were not touched */ if (!in->modified) @@ -1504,31 +1501,26 @@ qemuAgentSetVCPUsCommand(qemuAgentPtr agent, (*nmodified)++; - /* create single cpu object */ - cpu =3D virJSONValueNewObject(); - if (virJSONValueObjectAppendNumberInt(cpu, "logical-id", in->id) <= 0) - goto cleanup; + return -1; if (virJSONValueObjectAppendBoolean(cpu, "online", in->online) < 0) - goto cleanup; + return -1; if (virJSONValueArrayAppend(cpus, &cpu) < 0) - goto cleanup; + return -1; } - if (*nmodified =3D=3D 0) { - ret =3D 0; - goto cleanup; - } + if (*nmodified =3D=3D 0) + return 0; if (!(cmd =3D qemuAgentMakeCommand("guest-set-vcpus", "a:vcpus", &cpus, NULL))) - goto cleanup; + return -1; if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) - goto cleanup; + return -1; /* All negative values are invalid. Return of 0 is bogus since we woul= dn't * call the guest agent so that 0 cpus would be set successfully. Repo= rting @@ -1537,14 +1529,9 @@ qemuAgentSetVCPUsCommand(qemuAgentPtr agent, ret <=3D 0 || ret > *nmodified) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("guest agent returned malformed or invalid return= value")); - ret =3D -1; + return -1; } - cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); - virJSONValueFree(cpu); - virJSONValueFree(cpus); return ret; } --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1613152685; cv=none; d=zohomail.com; s=zohoarc; b=W/meqnR6YI8jb/T2lPvXuQLiQ1oVuP+27MZPK/FmYBfUzXtDKcKQz2k8OWuTqbQMvLML8z/wOb2JxjG1gY8Nay7PbxwEvJsAT1lnWSeuXS3bgpKV1u9VXH7sIxTRzdcNOuRYUZ0fIAZiLm4gENiwC/+pizuD0a8wXLi9HJ6lRkM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152685; 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=kfef1BUW9QAqturOTOC5b4MoH521/ZhvEyxYjYXIdZM=; b=QMsDOAUtX8BF/3WDZU3FemXwL2MOLIaX6tIOCuOJs4dPPKBWfCUQalfkDg145heUPs34g0xHxoXEG1EJn9j55eu4F8uHMi20ArTIi7sTLc1cAFTPedPQPq2leswRlptm1ox/Ar+EklagWBGAh+EQ+FO13BYC9axOttuon4/gkrU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1613152684697547.276234120364; Fri, 12 Feb 2021 09:58:04 -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-306-M9p0yBqEPY6R5gGCVUkdNg-1; Fri, 12 Feb 2021 12:57:36 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E747D188579E; Fri, 12 Feb 2021 17:57:03 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BDB9419D6C; Fri, 12 Feb 2021 17:57:03 +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 73DC958075; Fri, 12 Feb 2021 17:57:03 +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 11CHunDd011038 for ; Fri, 12 Feb 2021 12:56:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id 02FDB5C3E0; Fri, 12 Feb 2021 17:56:49 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 492235C23D for ; Fri, 12 Feb 2021 17:56:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152682; 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=kfef1BUW9QAqturOTOC5b4MoH521/ZhvEyxYjYXIdZM=; b=BeVwrH52eGy1V8Gw8thTBTBTBmGPYqsEolMSgJLCDp738lkgz3SSymFKZz2dedWD9KAYWs AzAXx0+zuNR39j+tR3biYDAHkeApe8SgdviY6OV3auIKk/gReAFpy6XEQe1+wzCvctY9Mh 2vZmJJkPFfCzvt4ump3pjIoaEGmYjr8= X-MC-Unique: M9p0yBqEPY6R5gGCVUkdNg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 23/25] virJSONParserHandle*: Refactor memory cleanup and drop NULL checks Date: Fri, 12 Feb 2021 18:55:36 +0100 Message-Id: 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.84 on 10.5.11.23 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" virJSONValueNew* won't return error nowadays so NULL checks are not necessary. The memory can be cleared via g_autoptr. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virjson.c | 68 ++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 44 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index 65215f03c5..de83441e27 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1604,17 +1604,13 @@ static int virJSONParserHandleNull(void *ctx) { virJSONParserPtr parser =3D ctx; - virJSONValuePtr value =3D virJSONValueNewNull(); + g_autoptr(virJSONValue) value =3D virJSONValueNewNull(); VIR_DEBUG("parser=3D%p", parser); - if (!value) + if (virJSONParserInsertValue(parser, value) < 0) return 0; - - if (virJSONParserInsertValue(parser, value) < 0) { - virJSONValueFree(value); - return 0; - } + value =3D NULL; return 1; } @@ -1625,17 +1621,13 @@ virJSONParserHandleBoolean(void *ctx, int boolean_) { virJSONParserPtr parser =3D ctx; - virJSONValuePtr value =3D virJSONValueNewBoolean(boolean_); + g_autoptr(virJSONValue) value =3D virJSONValueNewBoolean(boolean_); VIR_DEBUG("parser=3D%p boolean=3D%d", parser, boolean_); - if (!value) - return 0; - - if (virJSONParserInsertValue(parser, value) < 0) { - virJSONValueFree(value); + if (virJSONParserInsertValue(parser, value) < 0) return 0; - } + value =3D NULL; return 1; } @@ -1647,22 +1639,14 @@ virJSONParserHandleNumber(void *ctx, size_t l) { virJSONParserPtr parser =3D ctx; - char *str; - virJSONValuePtr value; - - str =3D g_strndup(s, l); - value =3D virJSONValueNewNumber(str); - VIR_FREE(str); + g_autofree char *str =3D g_strndup(s, l); + g_autoptr(virJSONValue) value =3D virJSONValueNewNumber(str); VIR_DEBUG("parser=3D%p str=3D%s", parser, str); - if (!value) + if (virJSONParserInsertValue(parser, value) < 0) return 0; - - if (virJSONParserInsertValue(parser, value) < 0) { - virJSONValueFree(value); - return 0; - } + value =3D NULL; return 1; } @@ -1674,18 +1658,14 @@ virJSONParserHandleString(void *ctx, size_t stringLen) { virJSONParserPtr parser =3D ctx; - virJSONValuePtr value =3D virJSONValueNewStringLen((const char *)strin= gVal, - stringLen); + g_autoptr(virJSONValue) value =3D virJSONValueNewStringLen((const char= *)stringVal, + stringLen); VIR_DEBUG("parser=3D%p str=3D%p", parser, (const char *)stringVal); - if (!value) - return 0; - - if (virJSONParserInsertValue(parser, value) < 0) { - virJSONValueFree(value); + if (virJSONParserInsertValue(parser, value) < 0) return 0; - } + value =3D NULL; return 1; } @@ -1716,21 +1696,21 @@ static int virJSONParserHandleStartMap(void *ctx) { virJSONParserPtr parser =3D ctx; - virJSONValuePtr value =3D virJSONValueNewObject(); + g_autoptr(virJSONValue) value =3D virJSONValueNewObject(); + virJSONValuePtr tmp =3D value; VIR_DEBUG("parser=3D%p", parser); - if (virJSONParserInsertValue(parser, value) < 0) { - virJSONValueFree(value); + if (virJSONParserInsertValue(parser, value) < 0) return 0; - } + value =3D NULL; if (VIR_REALLOC_N(parser->state, parser->nstate + 1) < 0) { return 0; } - parser->state[parser->nstate].value =3D value; + parser->state[parser->nstate].value =3D tmp; parser->state[parser->nstate].key =3D NULL; parser->nstate++; @@ -1765,20 +1745,20 @@ static int virJSONParserHandleStartArray(void *ctx) { virJSONParserPtr parser =3D ctx; - virJSONValuePtr value =3D virJSONValueNewArray(); + g_autoptr(virJSONValue) value =3D virJSONValueNewArray(); + virJSONValuePtr tmp =3D value; VIR_DEBUG("parser=3D%p", parser); - if (virJSONParserInsertValue(parser, value) < 0) { - virJSONValueFree(value); + if (virJSONParserInsertValue(parser, value) < 0) return 0; - } + value =3D NULL; if (VIR_REALLOC_N(parser->state, parser->nstate + 1) < 0) return 0; - parser->state[parser->nstate].value =3D value; + parser->state[parser->nstate].value =3D tmp; parser->state[parser->nstate].key =3D NULL; parser->nstate++; --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1613152658; cv=none; d=zohomail.com; s=zohoarc; b=Lzrju5SBrlyOqyNHDM+mMA9XKTnOu1qY+OlFyQbk5rpwwlAGE2/aPNBwiVxSmOSJKilxtDMJVETBoWEXk7+RbjMvv5niXcLcIpiltKGvGqcWlXmLxb927zyogmgUiHJAgFoTbvpa3eGqTCWu0ojBUIptV/zz7lZkbJycReMvioo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152658; 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=fcPt+q0OF0RPdo/gkfVhRGo+3z4FXx1y4gplscOffdo=; b=daVl1Nxm0iqLnT2yMKkfAKbQjr60xLIEUJkZ3Dlw0eFPttHcsnHFi5OvDtzmRrFWzCuteb73mk79xbn22wc9p9ZbB5byMIHnhEXG6HnO5GOmmxucjgz+45WSED3QzX4qgND6M7NXZTCks4ha+Q/RnmrwkhSwNpcXMFBl81aF+ko= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1613152658329773.4889325355613; Fri, 12 Feb 2021 09:57:38 -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-158-ex1fguKSOHymv6u8EXzc7A-1; Fri, 12 Feb 2021 12:57:34 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 49890C2B7; Fri, 12 Feb 2021 17:57:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 22C1F5D6AB; Fri, 12 Feb 2021 17:57:07 +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 E001758075; Fri, 12 Feb 2021 17:57:06 +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 11CHuoo5011048 for ; Fri, 12 Feb 2021 12:56:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id 290AA5C23D; Fri, 12 Feb 2021 17:56:50 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 767605C3E0 for ; Fri, 12 Feb 2021 17:56:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152656; 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=fcPt+q0OF0RPdo/gkfVhRGo+3z4FXx1y4gplscOffdo=; b=YlTFBgd8gDoVj4YFa5lSMX9xBiwWsV3LXswn+Aj5dgz1Uc6ZnPMq4P3iJMEaWB086JgQ6K 59F7YeTZP+2jS6GaioqnWs7+pNN7OeKcuKGqwIg45LMNfWw873Uso7WAPm8tcAzq6jI4fM fg7B5cFOISQyNoqTeezGu2NzXB6TfTg= X-MC-Unique: ex1fguKSOHymv6u8EXzc7A-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 24/25] virJSONValueNewNumber: Take ownership of passed string Date: Fri, 12 Feb 2021 18:55:37 +0100 Message-Id: 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.15 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" Avoid pointless copies of temporary strings when constructing number JSON objects. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virjson.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index de83441e27..b21b1fc63f 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -465,15 +465,22 @@ virJSONValueNewStringLen(const char *data, } +/** + * virJSONValueNewNumber: + * @data: string representing the number + * + * Creates a new virJSONValue of VIR_JSON_TYPE_NUMBER type. Note that this + * function takes ownership of @data. + */ static virJSONValuePtr -virJSONValueNewNumber(const char *data) +virJSONValueNewNumber(char *data) { virJSONValuePtr val; val =3D g_new0(virJSONValue, 1); val->type =3D VIR_JSON_TYPE_NUMBER; - val->data.number =3D g_strdup(data); + val->data.number =3D data; return val; } @@ -482,43 +489,35 @@ virJSONValueNewNumber(const char *data) virJSONValuePtr virJSONValueNewNumberInt(int data) { - g_autofree char *str =3D NULL; - str =3D g_strdup_printf("%i", data); - return virJSONValueNewNumber(str); + return virJSONValueNewNumber(g_strdup_printf("%i", data)); } virJSONValuePtr virJSONValueNewNumberUint(unsigned int data) { - g_autofree char *str =3D NULL; - str =3D g_strdup_printf("%u", data); - return virJSONValueNewNumber(str); + return virJSONValueNewNumber(g_strdup_printf("%u", data)); } virJSONValuePtr virJSONValueNewNumberLong(long long data) { - g_autofree char *str =3D NULL; - str =3D g_strdup_printf("%lld", data); - return virJSONValueNewNumber(str); + return virJSONValueNewNumber(g_strdup_printf("%lld", data)); } virJSONValuePtr virJSONValueNewNumberUlong(unsigned long long data) { - g_autofree char *str =3D NULL; - str =3D g_strdup_printf("%llu", data); - return virJSONValueNewNumber(str); + return virJSONValueNewNumber(g_strdup_printf("%llu", data)); } virJSONValuePtr virJSONValueNewNumberDouble(double data) { - g_autofree char *str =3D NULL; + char *str =3D NULL; if (virDoubleToStr(&str, data) < 0) return NULL; return virJSONValueNewNumber(str); @@ -1534,7 +1533,7 @@ virJSONValueCopy(const virJSONValue *in) out =3D virJSONValueNewString(in->data.string); break; case VIR_JSON_TYPE_NUMBER: - out =3D virJSONValueNewNumber(in->data.number); + out =3D virJSONValueNewNumber(g_strdup(in->data.number)); break; case VIR_JSON_TYPE_BOOLEAN: out =3D virJSONValueNewBoolean(in->data.boolean); @@ -1639,10 +1638,9 @@ virJSONParserHandleNumber(void *ctx, size_t l) { virJSONParserPtr parser =3D ctx; - g_autofree char *str =3D g_strndup(s, l); - g_autoptr(virJSONValue) value =3D virJSONValueNewNumber(str); + g_autoptr(virJSONValue) value =3D virJSONValueNewNumber(g_strndup(s, l= )); - VIR_DEBUG("parser=3D%p str=3D%s", parser, str); + VIR_DEBUG("parser=3D%p str=3D%s", parser, value->data.number); if (virJSONParserInsertValue(parser, value) < 0) return 0; --=20 2.29.2 From nobody Sun Apr 28 23:58:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1613152659; cv=none; d=zohomail.com; s=zohoarc; b=AQetzrFBS6u9y1yboxSLY1bJE+kus48Zt6tqaXNU6MRaypxP+k6UWTwnDG1h1Ijs7gj9ipqDn+RIAgJzpZhX0CTZx6pV+KqXOf4S91oBfgorbR+7+2KBfEVun/m93oTX9v4NYYPV5qlIwh7QMytMQz+H/C/IFFn7Y1REDc2UlN4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613152659; 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=Y/r20xcHEcqLLyPNkAyfUHyC36BwVf0naoAwEWD6Cho=; b=MTUKwzHG7/Z/qWOUNg7B03uooB1CqzjT+flV+Ttun2B72tH70IFcdQUxv0z8kpclMtjSauIg3h3qhjsmOQz+bfOxeXh5ueXldWcglufJXtbxCbUs0wvtq9Ej4kTvP9gVrizNhWqtW8QvtFOZ8tLLF8ajzQV0A58zVjpAJv9KDhQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1613152658521284.53270978685816; Fri, 12 Feb 2021 09:57:38 -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-376-bQoTUjNJOT-Uv6CTB7zSFQ-1; Fri, 12 Feb 2021 12:57:34 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C5D581DE1B; Fri, 12 Feb 2021 17:57:10 +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 89A9919D6C; Fri, 12 Feb 2021 17:57:10 +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 4E5AB18095C9; Fri, 12 Feb 2021 17:57:10 +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 11CHupub011057 for ; Fri, 12 Feb 2021 12:56:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5059367CC2; Fri, 12 Feb 2021 17:56:51 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8922E5C23D for ; Fri, 12 Feb 2021 17:56:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613152657; 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=Y/r20xcHEcqLLyPNkAyfUHyC36BwVf0naoAwEWD6Cho=; b=Y0u0jJBv7o5eih7MsZY2bfatUpM7yxTArpQkgkKk3X3qy16lVqrydF/qcF4wgKaHT5g/eo HTolsA7fc5iPpc/erwnRPGhqKOqNVw1xUA+DAOlhhl/UjPvCiqCH/esEWOoIXcT5O1V7Gb IGZHZP/z+a5I0z6SLlmI1rAXkKWZVrk= X-MC-Unique: bQoTUjNJOT-Uv6CTB7zSFQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 25/25] virJSONParserInsertValue: Take double pointer for @value Date: Fri, 12 Feb 2021 18:55:38 +0100 Message-Id: <74a6771a9f17c28ce3b9f2367733e0681676bf09.1613152442.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.84 on 10.5.11.23 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 calls virJSONValueObjectAppend/virJSONValueArrayAppend, so by taking a double pointer we can drop the pointer clearing from callers. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virjson.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index b21b1fc63f..b952ad500d 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1550,10 +1550,10 @@ virJSONValueCopy(const virJSONValue *in) #if WITH_YAJL static int virJSONParserInsertValue(virJSONParserPtr parser, - virJSONValuePtr value) + virJSONValuePtr *value) { if (!parser->head) { - parser->head =3D value; + parser->head =3D g_steal_pointer(value); } else { virJSONParserStatePtr state; if (!parser->nstate) { @@ -1572,7 +1572,7 @@ virJSONParserInsertValue(virJSONParserPtr parser, if (virJSONValueObjectAppend(state->value, state->key, - &value) < 0) + value) < 0) return -1; VIR_FREE(state->key); @@ -1585,7 +1585,7 @@ virJSONParserInsertValue(virJSONParserPtr parser, } if (virJSONValueArrayAppend(state->value, - &value) < 0) + value) < 0) return -1; } break; @@ -1607,9 +1607,8 @@ virJSONParserHandleNull(void *ctx) VIR_DEBUG("parser=3D%p", parser); - if (virJSONParserInsertValue(parser, value) < 0) + if (virJSONParserInsertValue(parser, &value) < 0) return 0; - value =3D NULL; return 1; } @@ -1624,9 +1623,8 @@ virJSONParserHandleBoolean(void *ctx, VIR_DEBUG("parser=3D%p boolean=3D%d", parser, boolean_); - if (virJSONParserInsertValue(parser, value) < 0) + if (virJSONParserInsertValue(parser, &value) < 0) return 0; - value =3D NULL; return 1; } @@ -1642,9 +1640,8 @@ virJSONParserHandleNumber(void *ctx, VIR_DEBUG("parser=3D%p str=3D%s", parser, value->data.number); - if (virJSONParserInsertValue(parser, value) < 0) + if (virJSONParserInsertValue(parser, &value) < 0) return 0; - value =3D NULL; return 1; } @@ -1661,9 +1658,8 @@ virJSONParserHandleString(void *ctx, VIR_DEBUG("parser=3D%p str=3D%p", parser, (const char *)stringVal); - if (virJSONParserInsertValue(parser, value) < 0) + if (virJSONParserInsertValue(parser, &value) < 0) return 0; - value =3D NULL; return 1; } @@ -1699,9 +1695,8 @@ virJSONParserHandleStartMap(void *ctx) VIR_DEBUG("parser=3D%p", parser); - if (virJSONParserInsertValue(parser, value) < 0) + if (virJSONParserInsertValue(parser, &value) < 0) return 0; - value =3D NULL; if (VIR_REALLOC_N(parser->state, parser->nstate + 1) < 0) { @@ -1748,9 +1743,8 @@ virJSONParserHandleStartArray(void *ctx) VIR_DEBUG("parser=3D%p", parser); - if (virJSONParserInsertValue(parser, value) < 0) + if (virJSONParserInsertValue(parser, &value) < 0) return 0; - value =3D NULL; if (VIR_REALLOC_N(parser->state, parser->nstate + 1) < 0) --=20 2.29.2