From nobody Mon Feb 9 01:20:38 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=1612178949; cv=none; d=zohomail.com; s=zohoarc; b=EPhtvUK+Y7cBHjumKCVQwooUBoGrT6+8BTu51fw+enGQzYjsv2VFhYy3GNQoN3mNCdqNJVVFaBWz1LLSnJzy76PlcQTA70sR/TTnZM6DScgFlTPbaNdtCucJqmtwLunkwwKAsHco6BVlpk/eiPrhCQu97095S2XTug1enycHaZI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612178949; 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=iDxHKgNS8NCtteGCWekT5cv4VWhHRJUDklcV/hvw++k=; b=LzTKPxEIuKmBPJ7g9gmlS2e0zc3nkTJQtfZscWes5vHkwCp8juKrR4CNpfHrMEkG5so/V0bHRLlM4ghHJuc+d1wLpNh7vTTw8Yk52n8me+DED+sRRfI76cDk3dkiIc7ENH0cxJxS1kAFDdqb034cr/s2hII+rK6x4v1XSbzDa6w= 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 1612178949265928.7931947880229; Mon, 1 Feb 2021 03:29:09 -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-206-VWKfDrCVP4awMKZRSnniPQ-1; Mon, 01 Feb 2021 06:29:06 -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 EAA81AFA80; Mon, 1 Feb 2021 11:29:00 +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 C903B72167; Mon, 1 Feb 2021 11:29:00 +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 9229B85F3; Mon, 1 Feb 2021 11:29:00 +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 111BSxKn003541 for ; Mon, 1 Feb 2021 06:28:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id 705436A912; Mon, 1 Feb 2021 11:28:59 +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 B10A26A90C; Mon, 1 Feb 2021 11:28:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612178948; 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=iDxHKgNS8NCtteGCWekT5cv4VWhHRJUDklcV/hvw++k=; b=OZlp1uW+7AYokk01fUrhOhniMoVoK0or/yrT0HjCVcERkSIHZ2SwL713usIszsphyO+Nf5 6krHzcJV6i7qh8V8bHTz0cE0oizufKeOhQycPz2m9HzgdqW7XAIgx0/zNrJorBGq3jJt5V 9HbmHLILHMSk4FiR4aOFSizjvADQK5U= X-MC-Unique: VWKfDrCVP4awMKZRSnniPQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 20/20] commandhelper: Use automatic memory management in main Date: Mon, 1 Feb 2021 12:28:04 +0100 Message-Id: <20210201112804.144366-21-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 | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index df9be7d424..bf6a5baa40 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -67,6 +67,12 @@ static void cleanupStringList(char ***ptr) free(strings); } =20 +static void cleanupFile(FILE **ptr) +{ + FILE *file =3D *ptr; + fclose(file); +} + static void cleanupGeneric(void *ptr) { void **ptrptr =3D ptr; @@ -330,42 +336,34 @@ static int printInput(struct Arguments *args) } =20 int main(int argc, char **argv) { - struct Arguments *args =3D parseArguments(argc, argv); - FILE *log =3D fopen(abs_builddir "/commandhelper.log", "w"); - int ret =3D EXIT_FAILURE; + cleanup(struct Arguments *, cleanupArguments) args =3D NULL; + cleanup(FILE *, cleanupFile) log =3D NULL; =20 - if (!log || !args) - goto cleanup; + if (!(log =3D fopen(abs_builddir "/commandhelper.log", "w"))) + return EXIT_FAILURE; + + if (!(args =3D parseArguments(argc, argv))) + return EXIT_FAILURE; =20 printArguments(log, argc, argv); =20 if (printEnvironment(log) !=3D 0) - goto cleanup; + return EXIT_FAILURE; =20 if (printFds(log) !=3D 0) - goto cleanup; + return EXIT_FAILURE; =20 printDaemonization(log, args); =20 if (printCwd(log) !=3D 0) - goto cleanup; + return EXIT_FAILURE; =20 fprintf(log, "UMASK:%04o\n", umask(0)); =20 if (printInput(args) !=3D 0) - goto cleanup; - - ret =3D EXIT_SUCCESS; + return EXIT_FAILURE; =20 - cleanup: - if (args) { - if (args->readfds) - free(args->readfds); - free(args); - } - if (log) - fclose(log); - return ret; + return EXIT_SUCCESS; } =20 #else --=20 2.26.2