From nobody Thu Mar 28 22:52:22 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; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602814731; cv=none; d=zohomail.com; s=zohoarc; b=MdAHvQJnwvOcQcz9b0XOjP7c8qCliO32J64/T8zZagqL24qkRBaXU0P/07myTF67yBFJk+uxpBKeF6K4GyX49sy3ryLwSux8CYwTlvs88txY/11yF9p/JGPxyJfKfbTkBKFO1hzUS2pM5Hj+kPElTNFQKS7gfrsieN76QSiOozg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602814731; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=tOg0clZ2D1nbCy2sRZr6eHKanJjK49jkZS4mc+HI6Sg=; b=moD74AfG6Yo9emVmB7lvzuVg7sIiqP9yOmUgbpaaHIahgxNFdGAPoaEBy6sc+yRnU5b2iPrrGZdyma28qD3bnRCak0MpQFrcKUpvj6cT9ACsOR+ULeJIc3/uVWRiRI8UcOvNxBetwrT4y/9Vml7mhaDrM2gw6RfykcUGBfUrVVM= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com 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 1602814731796128.65777712672264; Thu, 15 Oct 2020 19:18:51 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-312-64QUGvm6OdyHPjCXiRreKg-1; Thu, 15 Oct 2020 22:18:48 -0400 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 82A72186DD28; Fri, 16 Oct 2020 02:18:42 +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 C090D19C59; Fri, 16 Oct 2020 02:18: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 2DAF644A48; Fri, 16 Oct 2020 02:18:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09G2HrdX025994 for ; Thu, 15 Oct 2020 22:17:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4C7812011541; Fri, 16 Oct 2020 02:17:53 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 47446200A795 for ; Fri, 16 Oct 2020 02:17:51 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0DB61800186 for ; Fri, 16 Oct 2020 02:17:51 +0000 (UTC) Received: from regular1.263xmail.com (regular1.263xmail.com [211.150.70.203]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-35-hkQGQ2nNOCKoG7LqpunwZw-1; Thu, 15 Oct 2020 22:17:47 -0400 Received: from localhost (unknown [192.168.167.13]) by regular1.263xmail.com (Postfix) with ESMTP id D3B19867 for ; Fri, 16 Oct 2020 10:17:42 +0800 (CST) Received: from localhost.localdomain (unknown [14.18.236.70]) by smtp.263.net (postfix) whith ESMTP id P1670T140084844160768S1602814656270136_; Fri, 16 Oct 2020 10:17:42 +0800 (CST) X-MC-Unique: 64QUGvm6OdyHPjCXiRreKg-1 X-MC-Unique: hkQGQ2nNOCKoG7LqpunwZw-1 X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-ANTISPAM-LEVEL: 2 X-SKE-CHECKED: 1 X-ABS-CHECKED: 1 X-IP-DOMAINF: 1 X-UNIQUE-TAG: <6a8604e2bb58bec165bf95e5b6cdf563> X-RL-SENDER: yili@winhong.com X-SENDER: yili@winhong.com X-LOGIN-NAME: yili@winhong.com X-FST-TO: libvir-list@redhat.com X-SENDER-IP: 14.18.236.70 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 X-System-Flag: 0 From: Yi Li To: libvir-list@redhat.com Subject: [PATCH] qemuMonitorJSONCheckReply: Use g_autofree Date: Fri, 16 Oct 2020 10:17:33 +0800 Message-Id: <20201016021733.3854335-1-yili@winhong.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 09G2HrdX025994 X-loop: libvir-list@redhat.com Cc: yilikernel@gmail.com, yili@winhong.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 Content-Type: text/plain; charset="utf-8" Eliminate cleanup code by using g_autofree. Signed-off-by: Yi Li Reviewed-by: Daniel Henrique Barboza --- src/qemu/qemu_monitor_json.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 26ac499fc5..f76b369191 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -392,10 +392,11 @@ qemuMonitorJSONCheckErrorFull(virJSONValuePtr cmd, virJSONValuePtr reply, bool report) { + g_autofree char *cmdstr =3D virJSONValueToString(cmd, false); + g_autofree char *replystr =3D virJSONValueToString(reply, false); + if (virJSONValueObjectHasKey(reply, "error")) { virJSONValuePtr error =3D virJSONValueObjectGet(reply, "error"); - g_autofree char *cmdstr =3D virJSONValueToString(cmd, false); - g_autofree char *replystr =3D virJSONValueToString(reply, false); =20 /* Log the full JSON formatted command & error */ VIR_DEBUG("unable to execute QEMU command %s: %s", @@ -417,8 +418,6 @@ qemuMonitorJSONCheckErrorFull(virJSONValuePtr cmd, =20 return -1; } else if (!virJSONValueObjectHasKey(reply, "return")) { - g_autofree char *cmdstr =3D virJSONValueToString(cmd, false); - g_autofree char *replystr =3D virJSONValueToString(reply, false); =20 VIR_DEBUG("Neither 'return' nor 'error' is set in the JSON reply %= s: %s", NULLSTR(cmdstr), NULLSTR(replystr)); @@ -455,8 +454,8 @@ qemuMonitorJSONCheckReply(virJSONValuePtr cmd, =20 data =3D virJSONValueObjectGet(reply, "return"); if (virJSONValueGetType(data) !=3D type) { - char *cmdstr =3D virJSONValueToString(cmd, false); - char *retstr =3D virJSONValueToString(data, false); + g_autofree char *cmdstr =3D virJSONValueToString(cmd, false); + g_autofree char *retstr =3D virJSONValueToString(data, false); =20 VIR_DEBUG("Unexpected return type %d (expecting %d) for command %s= : %s", virJSONValueGetType(data), type, cmdstr, retstr); @@ -464,8 +463,6 @@ qemuMonitorJSONCheckReply(virJSONValuePtr cmd, _("unexpected type returned by QEMU command '%s'"), qemuMonitorJSONCommandName(cmd)); =20 - VIR_FREE(cmdstr); - VIR_FREE(retstr); return -1; } =20 --=20 2.25.3