From nobody Mon Feb 9 15:08:45 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=jym2qqHEgF61GnGI/WKvZWKO6Um7S7x0InHt2av27vdZt3s8erPScm8xkKGQkKV57t07UlKd0q6ip6nKJbhDCOe3NvIZcW1ZQ9Ngj2I1zLpgPNuRxP4pkPfbZJ5wtbNMl4CymVkScNdUyxP/roHx/y39wulE66OYAb2wNa1Zq7U= 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=+vef3nWgGH9xeYLxJ/O6ToQTCOqy1RYfQAVAo9U6uWk=; b=nscRIApOriI865++mmmDwD8aMRWE9xtzne146KmB80zvy74vYSdAF5RPBdWhZdjFQc9/C3b+OsOeV6PrCX0JAz/W4oPDBxGMR5uFxGBwj/qL/B0dv5qXsBOMU/Ah1HyLEEm2NA2r3HKcY2ZnSN7rfS0ufPYS71L6pr0J0CeFzK4= 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 1612178937610384.87657826273494; 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-326-jNahLOkfOcyzfhD6HliKdw-1; Mon, 01 Feb 2021 06:28:53 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 829591006C92; Mon, 1 Feb 2021 11:28:44 +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 5ECF960C64; Mon, 1 Feb 2021 11:28:44 +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 27B265003C; Mon, 1 Feb 2021 11:28:44 +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 111BSeo4003428 for ; Mon, 1 Feb 2021 06:28:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2D82169324; Mon, 1 Feb 2021 11:28:40 +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 723741840B; Mon, 1 Feb 2021 11:28:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612178934; 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=+vef3nWgGH9xeYLxJ/O6ToQTCOqy1RYfQAVAo9U6uWk=; b=Ji4Ti+H1wLn3ttM2UepVhxmUbUpxuiJWHlkYuI7A27ebvKqYDhJPFfPPhWUR8uBaDyZzZw ebx6TR5PT0EHZ2YfCBPVIuVNP+Ji7p974Yxzg0jqjAPoHFBICODn0r2ThGw1qWh7Q8PZgm RpMTAWHlCcXNXLuouSVlOKdCivkbb+I= X-MC-Unique: jNahLOkfOcyzfhD6HliKdw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 16/20] commandhelper: Use automatic memory management in parseArguments Date: Mon, 1 Feb 2021 12:28:00 +0100 Message-Id: <20210201112804.144366-17-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.12 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 | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 9f0b7f25ac..19dfc09151 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -24,7 +24,9 @@ #include #include =20 -#define VIR_NO_GLIB_STDIO /* This file intentionally does not link to libv= irt/glib */ +/* This file intentionally does not link to libvirt/glib */ +#define VIR_NO_GLIB_STDIO +#define cleanup(T, F) __attribute__((cleanup(F))) T #include "testutils.h" =20 #ifndef WIN32 @@ -42,17 +44,27 @@ struct Arguments { bool close_stdin; }; =20 +static void cleanupArguments(struct Arguments **ptr) +{ + struct Arguments *args =3D *ptr; + + if (args) + free(args->readfds); + + free(args); +} + static struct Arguments *parseArguments(int argc, char** argv) { - struct Arguments* args =3D NULL; - int ret =3D -1; + cleanup(struct Arguments *, cleanupArguments) args =3D NULL; + struct Arguments *ret; size_t i; =20 if (!(args =3D calloc(1, sizeof(*args)))) - goto cleanup; + return NULL; =20 if (!(args->readfds =3D calloc(1, sizeof(*args->readfds)))) - goto cleanup; + return NULL; =20 args->numreadfds =3D 1; args->readfds[0] =3D STDIN_FILENO; @@ -65,12 +77,12 @@ static struct Arguments *parseArguments(int argc, char*= * argv) (args->numreadfds + 1) * sizeof(*args->readfds)); if (!args->readfds) - goto cleanup; + return NULL; =20 if (1 !=3D sscanf(argv[i], "%u%c", &args->readfds[args->numreadfds++], &c)) { printf("Could not parse fd %s\n", argv[i]); - goto cleanup; + return NULL; } } else if (STREQ(argv[i], "--check-daemonize")) { args->daemonize_check =3D true; @@ -79,19 +91,9 @@ static struct Arguments *parseArguments(int argc, char**= argv) } } =20 - ret =3D 0; - - cleanup: - if (ret =3D=3D 0) - return args; - - if (args) { - if (args->readfds) - free(args->readfds); - free(args); - } - - return NULL; + ret =3D args; + args =3D NULL; + return ret; } =20 static void printArguments(FILE *log, int argc, char** argv) --=20 2.26.2