From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 2A5636DE0A5B for ; Sat, 26 Aug 2017 07:42:01 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[AWL=0.011, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id d2WNa0lqyVi0 for ; Sat, 26 Aug 2017 07:42:00 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 3F50C6DE0355 for ; Sat, 26 Aug 2017 07:42:00 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.89) (envelope-from ) id 1dlcEA-000394-8k; Sat, 26 Aug 2017 10:38:22 -0400 Received: (nullmailer pid 11254 invoked by uid 1000); Sat, 26 Aug 2017 14:41:55 -0000 From: David Bremner To: notmuch@notmuchmail.org, notmuch@freelists.org Subject: [PATCH 5/5] test/smtp-dummy: convert to 'goto DONE' style Date: Sat, 26 Aug 2017 11:41:41 -0300 Message-Id: <20170826144141.11140-6-david@tethera.net> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170826144141.11140-1-david@tethera.net> References: <20170826144141.11140-1-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 Aug 2017 14:42:01 -0000 Clean up several cppcheck warnings of the form - test/smtp-dummy.c:170: error: Resource leak: output Conform to overall notmuch code style. --- test/smtp-dummy.c | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/test/smtp-dummy.c b/test/smtp-dummy.c index fec2b8ad..71992edd 100644 --- a/test/smtp-dummy.c +++ b/test/smtp-dummy.c @@ -121,13 +121,14 @@ main (int argc, char *argv[]) { const char *progname; char *output_filename; - FILE *peer_file, *output; - int sock, peer, err; + FILE *peer_file = NULL, *output = NULL; + int sock = -1, peer, err; struct sockaddr_in addr, peer_addr; struct hostent *hostinfo; socklen_t peer_addr_len; int reuse; int background; + int ret = 0; progname = argv[0]; @@ -160,14 +161,16 @@ main (int argc, char *argv[]) if (output == NULL) { fprintf (stderr, "Failed to open %s for writing: %s\n", output_filename, strerror (errno)); - return 1; + ret = 1; + goto DONE; } sock = socket (AF_INET, SOCK_STREAM, 0); if (sock == -1) { fprintf (stderr, "Error: socket() failed: %s\n", strerror (errno)); - return 1; + ret = 1; + goto DONE; } reuse = 1; @@ -175,13 +178,15 @@ main (int argc, char *argv[]) if (err) { fprintf (stderr, "Error: setsockopt() failed: %s\n", strerror (errno)); - return 1; + ret = 1; + goto DONE; } hostinfo = gethostbyname ("localhost"); if (hostinfo == NULL) { fprintf (stderr, "Unknown host: localhost\n"); - return 1; + ret = 1; + goto DONE; } memset (&addr, 0, sizeof (addr)); @@ -193,7 +198,8 @@ main (int argc, char *argv[]) fprintf (stderr, "Error: bind() failed: %s\n", strerror (errno)); close (sock); - return 1; + ret = 1; + goto DONE; } err = listen (sock, 1); @@ -201,7 +207,8 @@ main (int argc, char *argv[]) fprintf (stderr, "Error: listen() failed: %s\n", strerror (errno)); close (sock); - return 1; + ret = 1; + goto DONE; } if (background) { @@ -210,13 +217,15 @@ main (int argc, char *argv[]) printf ("smtp_dummy_pid='%d'\n", pid); fflush (stdout); close (sock); - return 0; + ret = 0; + goto DONE; } if (pid < 0) { fprintf (stderr, "Error: fork() failed: %s\n", strerror (errno)); close (sock); - return 1; + ret = 1; + goto DONE; } /* Reached if pid == 0 (the child process). */ /* Close stdout so that the one interested in pid value will @@ -239,21 +248,27 @@ main (int argc, char *argv[]) if (peer == -1) { fprintf (stderr, "Error: accept() failed: %s\n", strerror (errno)); - return 1; + ret = 1; + goto DONE; } peer_file = fdopen (peer, "w+"); if (peer_file == NULL) { fprintf (stderr, "Error: fdopen() failed: %s\n", strerror (errno)); - return 1; + ret = 1; + goto DONE; } do_smtp_to_file (peer_file, output); - fclose (output); - fclose (peer_file); - close (sock); + DONE: + if (output) + fclose (output); + if (peer_file) + fclose (peer_file); + if (sock >= 0) + close (sock); - return 0; + return ret; } -- 2.14.1