From nobody Sat May 4 21:27:19 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=1603070302; cv=none; d=zohomail.com; s=zohoarc; b=J+0k8JjIorS54rDev7BM1LYLWsJy+MTHwtMN9xn7QK4Gp552bnTkTN4hzBhGYlvaRB9rB3Y7f8g+JeSMal8b+hGWkawRCUCZnbN5uGtS1lJT9kpX50693WpHpiIuKRdVn/417Rz4hpzrnLBnk/RbidWQmRJXJ9Mv8OebgKQmVa8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603070302; h=Content-Type:Content-Transfer-Encoding:Cc: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=W0vG2YkGuoGQmTtgZSjx1tYYvBznbHm5/rILElprKUA=; b=O7a4TFq0Vg3JIbxY9+wud1vQcsPTq1CFfAr8ml+ZCZ1x1oGvdTtqMqMM8PD2UT/Vp2TKpgVkzyRE0HDb69jHj5d6KKosZ8HpbfoPrjL51xvTtgeBeSRVWagdZhrxz7GYxEsQqSkgfttpxvRZeIQWy1NHsG7yFxUj1Rkz0YNuqD0= 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 1603070302401913.206619901848; Sun, 18 Oct 2020 18:18:22 -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-248-U7x3pLEzMRCS5g9D9t945w-1; Sun, 18 Oct 2020 21:18:19 -0400 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 CDF441084C88; Mon, 19 Oct 2020 01:18:11 +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 75A115D9EF; Mon, 19 Oct 2020 01:18:09 +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 5492144A6B; Mon, 19 Oct 2020 01:18:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09J1I19u014483 for ; Sun, 18 Oct 2020 21:18:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id B6FB612F99C; Mon, 19 Oct 2020 01:18:01 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B0BDE138A8A for ; Mon, 19 Oct 2020 01:17:57 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (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 B2339102F1E0 for ; Mon, 19 Oct 2020 01:17:57 +0000 (UTC) Received: from regular1.263xmail.com (regular1.263xmail.com [211.150.70.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-24-a44Jnc71M_yx9EVHO3wYyg-1; Sun, 18 Oct 2020 21:17:54 -0400 Received: from localhost (unknown [192.168.167.16]) by regular1.263xmail.com (Postfix) with ESMTP id E87F6FEA for ; Mon, 19 Oct 2020 09:17:50 +0800 (CST) Received: from localhost.localdomain (unknown [14.18.236.70]) by smtp.263.net (postfix) whith ESMTP id P30223T139798490638080S1603070266521422_; Mon, 19 Oct 2020 09:17:50 +0800 (CST) X-MC-Unique: U7x3pLEzMRCS5g9D9t945w-1 X-MC-Unique: a44Jnc71M_yx9EVHO3wYyg-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: X-RL-SENDER: yili@winhong.com X-SENDER: yili@winhong.com X-LOGIN-NAME: yili@winhong.com X-FST-TO: danielhb413@gmail.com X-SENDER-IP: 14.18.236.70 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 X-System-Flag: 0 From: Yi Li To: danielhb413@gmail.com, libvir-list@redhat.com Subject: [PATCH v2] qemu_monitor_json.c: use g_autofree Date: Mon, 19 Oct 2020 09:17:44 +0800 Message-Id: <20201019011744.3287454-1-yili@winhong.com> In-Reply-To: References: 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.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 09J1I19u014483 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.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 Content-Type: text/plain; charset="utf-8" Eliminate cleanup code by using g_autofree in qemuMonitorJSONCheckErrorFull= () and qemuMonitorJSONCheckReply Signed-off-by: Yi Li --- 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