public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf tools: Fix error handling of lzma decompression
@ 2016-08-21  7:57 Shawn Lin
  2016-08-24 14:25 ` Arnaldo Carvalho de Melo
  2016-09-05 13:19 ` [tip:perf/core] " tip-bot for Shawn Lin
  0 siblings, 2 replies; 3+ messages in thread
From: Shawn Lin @ 2016-08-21  7:57 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: Peter Zijlstra, linux-kernel, Shawn Lin

lzma_decompress_to_file never actually close the file
pointer, let's fix it.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

 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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-09-05 13:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-21  7:57 [PATCH] perf tools: Fix error handling of lzma decompression Shawn Lin
2016-08-24 14:25 ` Arnaldo Carvalho de Melo
2016-09-05 13:19 ` [tip:perf/core] " tip-bot for Shawn Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox