Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967688AbdIZHtU (ORCPT ); Tue, 26 Sep 2017 03:49:20 -0400 Received: from einhorn-mail.in-berlin.de ([217.197.80.20]:52874 "EHLO einhorn-mail.in-berlin.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964802AbdIZHtT (ORCPT ); Tue, 26 Sep 2017 03:49:19 -0400 X-Greylist: delayed 783 seconds by postgrey-1.27 at vger.kernel.org; Tue, 26 Sep 2017 03:49:18 EDT X-Envelope-From: stefanr@s5r6.in-berlin.de Date: Tue, 26 Sep 2017 09:35:23 +0200 From: Stefan Richter To: Martin Kepplinger Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH] tools: firewire: nosy-dump: fix a resource leak in main() Message-ID: <20170926093523.343c9a6c@kant> In-Reply-To: <20170913182116.24694-1-martink@posteo.de> References: <20170913182116.24694-1-martink@posteo.de> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 919 Lines: 29 On Sep 13 Martin Kepplinger wrote: > If option_input and option_output is true two files are opened > consecutively. In case the second fopen() fails, let's fclose() > the first one before returning early. > > Signed-off-by: Martin Kepplinger > --- > tools/firewire/nosy-dump.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/tools/firewire/nosy-dump.c b/tools/firewire/nosy-dump.c > index 3179c711bd65..228be406f206 100644 > --- a/tools/firewire/nosy-dump.c > +++ b/tools/firewire/nosy-dump.c > @@ -960,6 +960,8 @@ int main(int argc, const char *argv[]) > output = fopen(option_output, "w"); > if (output == NULL) { > fprintf(stderr, "Could not open %s, %m\n", option_output); > + if (input) > + fclose(input); > return -1; > } > } When we return from main(), all files are closed implicitly. -- Stefan Richter -======----= =--= ==-=- http://arcgraph.de/sr/