From nobody Sun Feb 8 22:21:19 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.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=1635159482; cv=none; d=zohomail.com; s=zohoarc; b=VpwN2a6C/VEdceO8YGGbrUPbAFwbHGtEnwDPJ6BCUNi/QtDRybNCqpGFMRZKc/pkKNWNlUzMcevraFBBsUt+V7WWTlY7FGg2A7EZqEPBsCbv2fc5XNMCHhGy7srE8YhGNUtJw053zMPKRVRUndrkjIrg4t469Kwj81emC7AvQ5k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635159482; 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=uj+BUybpTVjAlrm/dVSFSHFFneAsoDa6e/FAQJN1qoA=; b=Qy3wV7DitdZTlSdCQN1sdgZlRju94RIa3dWz/POD4C2SnzW/9VrAUlua+uO0cPorA0xZZFi78nHNLMOB7Y61EElkcKZRKkztYBv1UMCRxrFneXlmoFjFQ9Im5kDNArwl+7LeDK2GxQFWpd7ANhJATGUq03UMHmXTZYv2k/Xr0Uo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1635159482782334.8948734847098; Mon, 25 Oct 2021 03:58:02 -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-143-eaC4RHbxNC-fnb1pbuXnQQ-1; Mon, 25 Oct 2021 06:57:57 -0400 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 812CC9F92D; Mon, 25 Oct 2021 10:57: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 6425960862; Mon, 25 Oct 2021 10:57: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 2BDA51801241; Mon, 25 Oct 2021 10:57:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 19PAvopK016846 for ; Mon, 25 Oct 2021 06:57:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6641D5DD68; Mon, 25 Oct 2021 10:57:50 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id E23195DAA5 for ; Mon, 25 Oct 2021 10:57:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635159481; 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=uj+BUybpTVjAlrm/dVSFSHFFneAsoDa6e/FAQJN1qoA=; b=OusfX12xTXa136ZtuIuRXIBQQ07/sUOaibpA1SVJsZyYl7qvFZVGO9RPMaKoj9to0z3WWR Bwj+2OG6+Rt9GyyN72mtO6lj/Fj6Sh1CoMrmHIISC/MdOxDnN1OBsT62VONqTzWBrag8Tu nmr9kBm4HtkHRsiyTiS2fy9m03EyUbQ= X-MC-Unique: eaC4RHbxNC-fnb1pbuXnQQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 02/13] qemu_monitor_json: Don't transfer ownership to @msg Date: Mon, 25 Oct 2021 12:57:26 +0200 Message-Id: <0ec5f072e9c444fb57b190576ba8d1e752951ebe.1635159386.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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) X-ZM-MESSAGEID: 1635160384268100001 Content-Type: text/plain; charset="utf-8" In qemuMonitorJSONCommandWithFd() given command (represented by virJSONValue struct) is translated to string (represented by virBuffer). The ownership of the string is then transferred to the message which is then sent. The downside of this approach is we have to have an explicit call to free the string from the message. But if the message just "borrowed" the string (which it can safely do because it is just reading from the string) then automatic free of the buffer takes care of freeing the string. Signed-off-by: Michal Privoznik --- src/qemu/qemu_monitor.c | 2 +- src/qemu/qemu_monitor.h | 2 +- src/qemu/qemu_monitor_json.c | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 81d9087839..908ee0d302 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -420,7 +420,7 @@ static int qemuMonitorIOWrite(qemuMonitor *mon) { int done; - char *buf; + const char *buf; size_t len; =20 /* If no active message, or fully transmitted, the no-op */ diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index f452d0d306..2508e89503 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -39,7 +39,7 @@ typedef struct _qemuMonitorMessage qemuMonitorMessage; struct _qemuMonitorMessage { int txFD; =20 - char *txBuffer; + const char *txBuffer; int txOffset; int txLength; =20 diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index dcf9186191..6d8ccd91e8 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -322,7 +322,7 @@ qemuMonitorJSONCommandWithFd(qemuMonitor *mon, virBufferAddLit(&cmdbuf, "\r\n"); =20 msg.txLength =3D virBufferUse(&cmdbuf); - msg.txBuffer =3D virBufferContentAndReset(&cmdbuf); + msg.txBuffer =3D virBufferCurrentContent(&cmdbuf); msg.txFD =3D scm_fd; =20 ret =3D qemuMonitorSend(mon, &msg); @@ -338,8 +338,6 @@ qemuMonitorJSONCommandWithFd(qemuMonitor *mon, } =20 cleanup: - VIR_FREE(msg.txBuffer); - return ret; } =20 --=20 2.32.0