perf tools: Fix error handling of lzma decompression
PATCH 1/1 perf tools: Fix error handling of lzma decompression
lzma_decompress_to_file never actually close the file pointer, let's fix it.
Signed-off-by Shawn Lin <[email protected]>
---
tools/perf/util/lzma.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
tools/perf/util/lzma.c +12 -7
@@ -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; }
Signature · 1 line
2.3.7
Arnaldo Carvalho de Melo
maintainerEm Sun, Aug 21, 2016 at 03:57:33PM +0800, Shawn Lin escreveu:
Quoted 4 lines
lzma_decompress_to_filenever actually close the file pointer, let's fix it.Signed-off-by Shawn Lin <[email protected]>
Thanks, I changed the logic a bit to shorten the patch, this is how it ended up:
commit ffe67c2fabf128122b30fbf0ac498928e171b0b3
Author: Shawn Lin <[email protected]> Date: Sun Aug 21 15:57:33 2016 +0800
perf tools: Fix error handling of lzma decompression
lzma_decompress_to_file() never actually closes the file pointer, let's fix it.
Signed-off-by Shawn Lin <[email protected]>
Cc Peter Zijlstra <[email protected]>
[ Make err = -1, the common case, set it to 0 before the error label ]
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
tools/perf/util/lzma.c +9 -6
@@ -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 =-1 ;u8 buf_in[BUFSIZE ];u8 buf_out[BUFSIZE ];
@@ -45,7 +46,7 @@ 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 ; + goto err_fclose; } strm.next_in =NULL ;
@@ -60,7 +61,7 @@ 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 ; + goto err_fclose; }if (feof (infile))
@@ -74,7 +75,7 @@ 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 ; + goto err_fclose; } strm.next_out = buf_out;
@@ -83,13 +84,15 @@ int lzma_decompress_to_file(const char *input, int output_fd)if (ret !=LZMA_OK ) {if (ret ==LZMA_STREAM_END ) -return 0 ; +break ;pr_err ("lzma: failed %s\n" ,lzma_strerror (ret)); -return -1 ; + goto err_fclose; } } + err =0 ; +err_fclose:fclose (infile); -return 0 ; +return err; }
Quoted 68 lines
tools/perf/util/lzma.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)tools/perf/util/lzma.c +12
-7@@ -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; }Signature · 1 line
2.3.7
tip-bot for Shawn Lin
merge botperf tools: Fix error handling of lzma decompression
Commit-ID: ffe67c2fabf128122b30fbf0ac498928e171b0b3 Gitweb: http://git.kernel.org/tip/ffe67c2fabf128122b30fbf0ac498928e171b0b3 Author: Shawn Lin <[email protected]> AuthorDate: Sun, 21 Aug 2016 15:57:33 +0800 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 24 Aug 2016 11:20:58 -0300
perf tools: Fix error handling of lzma decompression
lzma_decompress_to_file() never actually closes the file pointer, let's fix it.
Signed-off-by Shawn Lin <[email protected]>
Cc Peter Zijlstra <[email protected]>
[ Make err = -1, the common case, set it to 0 before the error label ]
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/util/lzma.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
tools/perf/util/lzma.c +9 -6
@@ -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 =-1 ;u8 buf_in[BUFSIZE ];u8 buf_out[BUFSIZE ];
@@ -45,7 +46,7 @@ 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 ; + goto err_fclose; } strm.next_in =NULL ;
@@ -60,7 +61,7 @@ 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 ; + goto err_fclose; }if (feof (infile))
@@ -74,7 +75,7 @@ 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 ; + goto err_fclose; } strm.next_out = buf_out;
@@ -83,13 +84,15 @@ int lzma_decompress_to_file(const char *input, int output_fd)if (ret !=LZMA_OK ) {if (ret ==LZMA_STREAM_END ) -return 0 ; +break ;pr_err ("lzma: failed %s\n" ,lzma_strerror (ret)); -return -1 ; + goto err_fclose; } } + err =0 ; +err_fclose:fclose (infile); -return 0 ; +return err; }