From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752546AbcHUICX (ORCPT ); Sun, 21 Aug 2016 04:02:23 -0400 Received: from lucky1.263xmail.com ([211.157.147.135]:45365 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751651AbcHUICV (ORCPT ); Sun, 21 Aug 2016 04:02:21 -0400 X-263anti-spam: KSV:0; X-MAIL-GRAY: 1 X-MAIL-DELIVERY: 0 X-KSVirus-check: 0 X-ABS-CHECKED: 4 X-ADDR-CHECKED: 0 X-RL-SENDER: shawn.lin@rock-chips.com X-FST-TO: acme@kernel.org X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: shawn.lin@rock-chips.com X-UNIQUE-TAG: <02c3964edf36233eeeaa06c2d66a0177> X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 From: Shawn Lin To: Arnaldo Carvalho de Melo , Ingo Molnar Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Shawn Lin Subject: [PATCH] perf tools: Fix error handling of lzma decompression Date: Sun, 21 Aug 2016 15:57:33 +0800 Message-Id: <1471766253-1964-1-git-send-email-shawn.lin@rock-chips.com> X-Mailer: git-send-email 1.8.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org lzma_decompress_to_file never actually close the file pointer, let's fix it. Signed-off-by: Shawn Lin --- tools/perf/util/lzma.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/lzma.c b/tools/perf/util/lzma.c index 95a1acb..a95d473 100644 --- a/tools/perf/util/lzma.c +++ b/tools/perf/util/lzma.c @@ -29,6 +29,7 @@ int lzma_decompress_to_file(const char *input, int output_fd) lzma_action action = LZMA_RUN; lzma_stream strm = LZMA_STREAM_INIT; lzma_ret ret; + int err = 0; u8 buf_in[BUFSIZE]; u8 buf_out[BUFSIZE]; @@ -45,7 +46,8 @@ int lzma_decompress_to_file(const char *input, int output_fd) if (ret != LZMA_OK) { pr_err("lzma: lzma_stream_decoder failed %s (%d)\n", lzma_strerror(ret), ret); - return -1; + err = -1; + goto err_fclose; } strm.next_in = NULL; @@ -60,7 +62,8 @@ int lzma_decompress_to_file(const char *input, int output_fd) if (ferror(infile)) { pr_err("lzma: read error: %s\n", strerror(errno)); - return -1; + err = -1; + goto err_fclose; } if (feof(infile)) @@ -74,7 +77,8 @@ int lzma_decompress_to_file(const char *input, int output_fd) if (writen(output_fd, buf_out, write_size) != write_size) { pr_err("lzma: write error: %s\n", strerror(errno)); - return -1; + err = -1; + goto err_fclose; } strm.next_out = buf_out; @@ -83,13 +87,14 @@ int lzma_decompress_to_file(const char *input, int output_fd) if (ret != LZMA_OK) { if (ret == LZMA_STREAM_END) - return 0; + goto err_fclose; pr_err("lzma: failed %s\n", lzma_strerror(ret)); - return -1; + err = -1; + goto err_fclose; } } - +err_fclose: fclose(infile); - return 0; + return err; } -- 2.3.7