Skip to content

Commit

Permalink
perf tools: Fix error handling of lzma decompression
Browse files Browse the repository at this point in the history
lzma_decompress_to_file() never actually closes the file pointer, let's
fix it.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1471766253-1964-1-git-send-email-shawn.lin@rock-chips.com
[ Make err = -1, the common case, set it to 0 before the error label ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Shawn Lin authored and Arnaldo Carvalho de Melo committed Aug 24, 2016
1 parent 04e1196 commit ffe67c2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tools/perf/util/lzma.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand All @@ -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))
Expand All @@ -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;
Expand All @@ -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;
}

0 comments on commit ffe67c2

Please sign in to comment.