Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751459AbdIMSVh (ORCPT ); Wed, 13 Sep 2017 14:21:37 -0400 Received: from mout02.posteo.de ([185.67.36.66]:48092 "EHLO mout02.posteo.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751106AbdIMSVd (ORCPT ); Wed, 13 Sep 2017 14:21:33 -0400 From: Martin Kepplinger To: stefanr@s5r6.in-berlin.de Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Martin Kepplinger Subject: [PATCH] tools: firewire: nosy-dump: fix a resource leak in main() Date: Wed, 13 Sep 2017 20:21:16 +0200 Message-Id: <20170913182116.24694-1-martink@posteo.de> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 723 Lines: 24 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; } } -- 2.11.0