From nobody Sun Feb 8 17:03:50 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=1634301639; cv=none; d=zohomail.com; s=zohoarc; b=k/fi4WNz0t/sRSZIqvOtV2jeWCBTNaqOYnQMVVUN0D0Oz1EYtuAv06/PvMrlnmvWKwYw0xbDffB7FXMUvelfUZ1yvE5Xicdd7+AYaRBxvF55FExJ6oOoeiYSRQ8NhryKql6fag7Lyz9CWwGWma4U3EaKnl+3/eAB0PbWviUqXGE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1634301639; 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=OJ9mdzoZ+4NsUhpwgSEClAPjaJiCCrbjcvEjB4+dAaY=; b=bRus1rH9nGyGkLk//2Lli6CfHGOkEmcXi3E38WfQ55c1Pu5gx7yZa7NAKQs0PpGhW458fLiGURG+fxVe0E8RZ/XAlRBqUGsMuRTEOzGFm7mCmTWesjpIXYXOULzKMbHwrJGTPvGgkehid+RlEmgc5FQDptLyAq4haiU6rriYFHA= 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) 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 163430163954212.266497622734391; Fri, 15 Oct 2021 05:40:39 -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-363-kW2oG0YcOeCWVvkeHA6PFg-1; Fri, 15 Oct 2021 08:40:34 -0400 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 D6B7718125C0; Fri, 15 Oct 2021 12:40:29 +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 15C4957CD0; Fri, 15 Oct 2021 12:40: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 908174A703; Fri, 15 Oct 2021 12:40:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 19FCWPEO016781 for ; Fri, 15 Oct 2021 08:32:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id BF7CC196E5; Fri, 15 Oct 2021 12:32:25 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 48E2219736 for ; Fri, 15 Oct 2021 12:32:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634301638; 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=OJ9mdzoZ+4NsUhpwgSEClAPjaJiCCrbjcvEjB4+dAaY=; b=bO65M5j+oDv5/8t3HYXzVc7v1Gp9kIfSjPGyP9pBEVhR0Cb0t+skv5lalPIOcxXbJ6hPJO f+XMxWTxyxiq632Ggi9Hj8WtQLelwEya6JLuAJY180cY/HP+IggO6UdgV+PWp7pjemWa1J rTXZMYX1SScAiAvWsKZ73i+VbQSlBx4= X-MC-Unique: kW2oG0YcOeCWVvkeHA6PFg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/2] virnetsocket: Don't free virCommand in virNetSocketNewConnectCommand() Date: Fri, 15 Oct 2021 14:32:07 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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) X-ZM-MESSAGEID: 1634301641124100001 Content-Type: text/plain; charset="utf-8" The aim of virNetSocketNewConnectCommand() is to execute passed command and attach socket pair/pipe to it so that client socket can be opened (this is used for connections with alternative transports, e.g. ssh). The virCommand is created in a caller and then passed to virNetSocketNewConnectCommand() where it is freed using virCommandFree(). This approach is wrong on two levels: 1) The deallocation happens on a different level than allocation, 2) There's a WIN32 stub that just reports an error and doesn't free the command. However, with g_autoptr() trickery the command can be freed in caller. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/rpc/virnetsocket.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index 212089520d..50c0c4ecc8 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -821,8 +821,6 @@ int virNetSocketNewConnectCommand(virCommand *cmd, if (!(*retsock =3D virNetSocketNew(NULL, NULL, true, sv[0], errfd[0], = pid, false))) goto error; =20 - virCommandFree(cmd); - return 0; =20 error: @@ -832,7 +830,6 @@ int virNetSocketNewConnectCommand(virCommand *cmd, VIR_FORCE_CLOSE(errfd[1]); =20 virCommandAbort(cmd); - virCommandFree(cmd); =20 return -1; } @@ -856,7 +853,7 @@ int virNetSocketNewConnectSSH(const char *nodename, const char *command, virNetSocket **retsock) { - virCommand *cmd; + g_autoptr(virCommand) cmd =3D NULL; =20 *retsock =3D NULL; =20 @@ -1154,7 +1151,7 @@ virNetSocketNewConnectLibssh(const char *host G_GNUC_= UNUSED, int virNetSocketNewConnectExternal(const char **cmdargv, virNetSocket **retsock) { - virCommand *cmd; + g_autoptr(virCommand) cmd =3D NULL; =20 *retsock =3D NULL; =20 --=20 2.32.0