From nobody Sun Feb 8 18:33:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606762577; cv=none; d=zohomail.com; s=zohoarc; b=nO9jS06funrv7Bbo+VsHfjY9yPss8IHJz9cJSmQpNW7bJY0kkB4xmjeh7xVV7K0XrKTisNWiYj6/FWF9q6iuJjgdQ6JP+pxtbfiOrmJvEICpzhuOlc2+nrB/FITeC2VhK4CiH57S0+2h6NPgYrd2T+frSorjCUBaoNKtu8lTSNo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606762577; 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=m/b0xiuV/7/gyUxvdGsaR1vQXaW2KXIP0U/Uf+96fFY=; b=MJBvEKwD3qA8uj/KsSeaCkEn1m5UHH6eObzqpKka1N3C9IQyyT78AWKZ9znYrUa+CqW8lUKBEJvTPxD83xy0qPpNm/3b/UY2NeVcLTJcRoPlKD3EtYuqajjRot9tZMzeB/nbM7Aw94sF3kOtzVtWfG1ohjktQvx58KYaSpeT4E8= 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 1606762577677881.7359827495555; Mon, 30 Nov 2020 10:56: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-171-oZIxO-5DMdWXRNjxvUBbSw-1; Mon, 30 Nov 2020 13:56:13 -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 07F8D8030C9; Mon, 30 Nov 2020 18:56:05 +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 D6D9619D80; Mon, 30 Nov 2020 18:56:04 +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 A04FD1809CA9; Mon, 30 Nov 2020 18:56:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AUItndj014206 for ; Mon, 30 Nov 2020 13:55:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id C763660C67; Mon, 30 Nov 2020 18:55:49 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16A2660BE2 for ; Mon, 30 Nov 2020 18:55:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606762576; 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=m/b0xiuV/7/gyUxvdGsaR1vQXaW2KXIP0U/Uf+96fFY=; b=EiYPKkc0duxMdfMDimb367k+XdjvG8gQrWxyhzdAeCIVpTYs5M77QA/9Hk/HzqBKpGLB7m tO99AvrYwMeuQKyybqsLt8WOn3CMz/mGSKh8IFpj5zY4YhZ2b5M4I1E/Y5NI/xLXIVxxBJ WsnOg46vbqp2IfvU67Q/qk1fAQNIj0M= X-MC-Unique: oZIxO-5DMdWXRNjxvUBbSw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 06/24] qemuMonitorJSONMakeCommandInternal: Clear @arguments when stolen Date: Mon, 30 Nov 2020 19:55:19 +0100 Message-Id: <12bd2d40dbb4b1b5d178c70963d1df357e58aeef.1606762033.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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" All callers of qemuMonitorJSONMakeCommandInternal will benefit from making @arguments a double pointer and passing it to virJSONValueObjectCreate directly which will clear it if it steals the value. Signed-off-by: Peter Krempa --- src/qemu/qemu_monitor_json.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index fbcd1d8e08..272f7a9433 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -546,20 +546,18 @@ qemuMonitorJSONTransactionAdd(virJSONValuePtr actions, * * Create a JSON object used on the QMP monitor to call a command. * - * Note that @arguments is always consumed and should not be referenced af= ter - * the call to this function. + * Note that @arguments is consumed and cleared. */ static virJSONValuePtr qemuMonitorJSONMakeCommandInternal(const char *cmdname, - virJSONValuePtr arguments) + virJSONValuePtr *arguments) { virJSONValuePtr ret =3D NULL; ignore_value(virJSONValueObjectCreate(&ret, "s:execute", cmdname, - "A:arguments", &arguments, NULL)= ); + "A:arguments", arguments, NULL)); - virJSONValueFree(arguments); return ret; } @@ -569,7 +567,7 @@ qemuMonitorJSONMakeCommand(const char *cmdname, ...) { virJSONValuePtr obj =3D NULL; - virJSONValuePtr jargs =3D NULL; + g_autoptr(virJSONValue) jargs =3D NULL; va_list args; va_start(args, cmdname); @@ -577,7 +575,7 @@ qemuMonitorJSONMakeCommand(const char *cmdname, if (virJSONValueObjectCreateVArgs(&jargs, args) < 0) goto cleanup; - obj =3D qemuMonitorJSONMakeCommandInternal(cmdname, jargs); + obj =3D qemuMonitorJSONMakeCommandInternal(cmdname, &jargs); cleanup: va_end(args); @@ -3505,9 +3503,8 @@ qemuMonitorJSONSetMigrationParams(qemuMonitorPtr mon, { g_autoptr(virJSONValue) cmd =3D NULL; g_autoptr(virJSONValue) reply =3D NULL; - virJSONValuePtr par =3D g_steal_pointer(params); - if (!(cmd =3D qemuMonitorJSONMakeCommandInternal("migrate-set-paramete= rs", par))) + if (!(cmd =3D qemuMonitorJSONMakeCommandInternal("migrate-set-paramete= rs", params))) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) @@ -4024,7 +4021,7 @@ int qemuMonitorJSONAddFileHandleToSet(qemuMonitorPtr = mon, return -1; } - if (!(cmd =3D qemuMonitorJSONMakeCommandInternal("add-fd", g_steal_poi= nter(&args)))) + if (!(cmd =3D qemuMonitorJSONMakeCommandInternal("add-fd", &args))) return -1; if (qemuMonitorJSONCommandWithFd(mon, cmd, fd, &reply) < 0) @@ -4208,9 +4205,8 @@ qemuMonitorJSONAddNetdev(qemuMonitorPtr mon, { g_autoptr(virJSONValue) cmd =3D NULL; g_autoptr(virJSONValue) reply =3D NULL; - virJSONValuePtr pr =3D g_steal_pointer(props); - if (!(cmd =3D qemuMonitorJSONMakeCommandInternal("netdev_add", pr))) + if (!(cmd =3D qemuMonitorJSONMakeCommandInternal("netdev_add", props))) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) @@ -4637,9 +4633,8 @@ qemuMonitorJSONAddObject(qemuMonitorPtr mon, { g_autoptr(virJSONValue) cmd =3D NULL; g_autoptr(virJSONValue) reply =3D NULL; - virJSONValuePtr pr =3D g_steal_pointer(props); - if (!(cmd =3D qemuMonitorJSONMakeCommandInternal("object-add", pr))) + if (!(cmd =3D qemuMonitorJSONMakeCommandInternal("object-add", props))) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) @@ -7506,9 +7501,8 @@ qemuMonitorJSONBlockExportAdd(qemuMonitorPtr mon, { g_autoptr(virJSONValue) cmd =3D NULL; g_autoptr(virJSONValue) reply =3D NULL; - virJSONValuePtr pr =3D g_steal_pointer(props); - if (!(cmd =3D qemuMonitorJSONMakeCommandInternal("block-export-add", p= r))) + if (!(cmd =3D qemuMonitorJSONMakeCommandInternal("block-export-add", p= rops))) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) @@ -9036,9 +9030,8 @@ qemuMonitorJSONBlockdevAdd(qemuMonitorPtr mon, { g_autoptr(virJSONValue) cmd =3D NULL; g_autoptr(virJSONValue) reply =3D NULL; - virJSONValuePtr pr =3D g_steal_pointer(props); - if (!(cmd =3D qemuMonitorJSONMakeCommandInternal("blockdev-add", pr))) + if (!(cmd =3D qemuMonitorJSONMakeCommandInternal("blockdev-add", props= ))) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) @@ -9057,9 +9050,8 @@ qemuMonitorJSONBlockdevReopen(qemuMonitorPtr mon, { g_autoptr(virJSONValue) cmd =3D NULL; g_autoptr(virJSONValue) reply =3D NULL; - virJSONValuePtr pr =3D g_steal_pointer(props); - if (!(cmd =3D qemuMonitorJSONMakeCommandInternal("blockdev-reopen", pr= ))) + if (!(cmd =3D qemuMonitorJSONMakeCommandInternal("blockdev-reopen", pr= ops))) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) --=20 2.28.0