From nobody Mon Feb 9 13:35:31 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=1612178937; cv=none; d=zohomail.com; s=zohoarc; b=QHGyhUJYEg5yFpB5HsuXYudNJkcibTn1XbknRdp0MPergZlKHMM3/ZY5uU4LgQqGZ+G6vtvrG96VoFFwUUjT6fA4iUu4WfUoI+NjdgfkutOYbkUrUtCmv7zmYgJQ2bYZy8M5K79NiKLByA02wQGtmZWuxUAEZJeg8uIJVIp9nG8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612178937; 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=Nke8viukJD9iULU4OVQ2QI5FmKwFxXFpn+S3JvNNfy8=; b=ktl5c1sMHBboIYx4RDuj6+rVaRhXBquXv2czeawx6FSSwLeq/xG43Pk/b3FYshPP1euCqbRvL64KGsuK1fL1n5ZxFv8M3RVx1zEgAv+fjP5epA/zq0hOJKDmvBbndymLT6vHFxblwmusj/70k5Iwse1X6K/HX323V4/0VpnCDXU= 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 1612178937954801.3436300450339; Mon, 1 Feb 2021 03:28:57 -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-294-VRRLDzoTNAykrrSPxxRzGg-1; Mon, 01 Feb 2021 06:28:53 -0500 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 64C92AFA8A; Mon, 1 Feb 2021 11:28:47 +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 444A67216F; Mon, 1 Feb 2021 11:28:47 +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 0ED9D50044; Mon, 1 Feb 2021 11:28:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSfQw003435 for ; Mon, 1 Feb 2021 06:28:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id 39E8969324; Mon, 1 Feb 2021 11:28:41 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8098D1840B; Mon, 1 Feb 2021 11:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612178936; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=Nke8viukJD9iULU4OVQ2QI5FmKwFxXFpn+S3JvNNfy8=; b=O8V/W9wzbVzxcdU/kkenz7ix+2JLLqZn9WQC3eiBAWAwH/tdfvfVtiiOSjHX0tMyO27TTj V8nyxZeagBarC90CHT9qrZ+jAfFlX8CMMBOpZ1DTJStRGAS1ql4rx7Uf4XLH3bXHEPeNj6 Ug5sBZOPp+qdbd81M3s0/N02jhQivJY= X-MC-Unique: VRRLDzoTNAykrrSPxxRzGg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 17/20] commandhelper: Use automatic memory management in printEnvironment Date: Mon, 1 Feb 2021 12:28:01 +0100 Message-Id: <20210201112804.144366-18-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake --- tests/commandhelper.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 19dfc09151..854f3c09bf 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -54,6 +54,12 @@ static void cleanupArguments(struct Arguments **ptr) free(args); } =20 +static void cleanupGeneric(void *ptr) +{ + void **ptrptr =3D ptr; + free (*ptrptr); +} + static struct Arguments *parseArguments(int argc, char** argv) { cleanup(struct Arguments *, cleanupArguments) args =3D NULL; @@ -124,16 +130,15 @@ static int envsort(const void *a, const void *b) =20 static int printEnvironment(FILE *log) { - char **newenv; + cleanup(char **, cleanupGeneric) newenv =3D NULL; size_t length; size_t i; - int ret =3D -1; =20 for (length =3D 0; environ[length]; length++) { } =20 if (!(newenv =3D malloc(sizeof(*newenv) * length))) - goto cleanup; + return -1; =20 for (i =3D 0; i < length; i++) { newenv[i] =3D environ[i]; @@ -148,12 +153,7 @@ static int printEnvironment(FILE *log) fprintf(log, "ENV:%s\n", newenv[i]); } =20 - ret =3D 0; - - cleanup: - if (newenv) - free(newenv); - return ret; + return 0; } =20 static int printFds(FILE *log) --=20 2.26.2