From nobody Mon Feb 9 01:00:53 2026 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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=1614183544; cv=none; d=zohomail.com; s=zohoarc; b=HC2MHi+Jc23BrBCLZrWOrv1XwRsQRZnAWaC3djgp3FRLdZyBTzlq2NMh4GBRfHpAK2Y3fEzi2SWVhmmD9szrkIaKbmM3HBsWGbGDgun+1SjecbTNonbcHdWngReMQ4b1+PUmPObA59QizdHZbDTQDklSkGG0rvNI9luINoyJxcQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614183544; 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=1pM4vuZy9BqsBOh2PlZLeYNl7CMi1oC09II6U3scA9U=; b=DLPOl7y4oAfBw8k8m+RoigkK1zVjrs01/AVEyegnTg5i/eedVssnyeCSYfwpwjJP1815F5FYdvLRaBphf3n3u74XQdgAaSDSSAL25mjyr01vm/c3Ah/GjQ2PSprf2lk9SfI4qZzKupBs2QDWtXdGCdIjlMLY/0D2LDGso7VS+MY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1614183544179370.25639999157477; Wed, 24 Feb 2021 08:19:04 -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-275-AznUyQDuOUycQ_2srGFLQw-1; Wed, 24 Feb 2021 11:17:46 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C4CD1107ACF4; Wed, 24 Feb 2021 16:17:35 +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 9285210016FD; Wed, 24 Feb 2021 16:17:35 +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 5726518095CD; Wed, 24 Feb 2021 16:17:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11OGHK2e015502 for ; Wed, 24 Feb 2021 11:17:20 -0500 Received: by smtp.corp.redhat.com (Postfix) id 063CE646DC; Wed, 24 Feb 2021 16:17:20 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22CA960862 for ; Wed, 24 Feb 2021 16:17:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614183543; 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=1pM4vuZy9BqsBOh2PlZLeYNl7CMi1oC09II6U3scA9U=; b=a9Ypq379SOIwNs3wmkuO2ZqeC3cgPF+h31APxRDNBBgn/QyDhlrtTSNz5VXTIK8p+1wyQe hwGpK/OhuNbzuEG69G94iT5cdSgH/WbP9lARSYWGzodXMGB4+f6uOloABoxQ0GPoy1hVFp nXMtkYBMJWIdKVkPAfoL6mtmd7CMU04= X-MC-Unique: AznUyQDuOUycQ_2srGFLQw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 04/33] virCommandAddEnv: Make stealing of argument more obvious Date: Wed, 24 Feb 2021 17:16:39 +0100 Message-Id: <6f36d6f77b8e888a16535209b09fc05baeb9d1e3.1614182583.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.22 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" The function is supposed to always consume the passed environment variable string. Use a temp variable with autofree and g_steal_pointer to prevent having to free it manually. Signed-off-by: Peter Krempa --- src/util/vircommand.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 323f841b98..b94ab615d5 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -1325,8 +1325,10 @@ virCommandRawStatus(virCommandPtr cmd) * already set, then it is replaced in the list. */ static void -virCommandAddEnv(virCommandPtr cmd, char *env) +virCommandAddEnv(virCommandPtr cmd, + char *envstr) { + g_autofree char *env =3D envstr; size_t namelen; size_t i; @@ -1336,19 +1338,18 @@ virCommandAddEnv(virCommandPtr cmd, char *env) /* + 1 because we want to match the '=3D' character too. */ if (STREQLEN(cmd->env[i], env, namelen + 1)) { VIR_FREE(cmd->env[i]); - cmd->env[i] =3D env; + cmd->env[i] =3D g_steal_pointer(&env); return; } } /* Arg plus trailing NULL. */ if (VIR_RESIZE_N(cmd->env, cmd->maxenv, cmd->nenv, 1 + 1) < 0) { - VIR_FREE(env); cmd->has_error =3D ENOMEM; return; } - cmd->env[cmd->nenv++] =3D env; + cmd->env[cmd->nenv++] =3D g_steal_pointer(&env); } /** --=20 2.29.2