Skip to content

Commit ffe67c2

Browse files
shawn1221acmel
authored andcommitted
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]> Link: http://lkml.kernel.org/r/[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]>
1 parent 04e1196 commit ffe67c2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

tools/perf/util/lzma.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ int lzma_decompress_to_file(const char *input, int output_fd)
2929
lzma_action action = LZMA_RUN;
3030
lzma_stream strm = LZMA_STREAM_INIT;
3131
lzma_ret ret;
32+
int err = -1;
3233

3334
u8 buf_in[BUFSIZE];
3435
u8 buf_out[BUFSIZE];
@@ -45,7 +46,7 @@ int lzma_decompress_to_file(const char *input, int output_fd)
4546
if (ret != LZMA_OK) {
4647
pr_err("lzma: lzma_stream_decoder failed %s (%d)\n",
4748
lzma_strerror(ret), ret);
48-
return -1;
49+
goto err_fclose;
4950
}
5051

5152
strm.next_in = NULL;
@@ -60,7 +61,7 @@ int lzma_decompress_to_file(const char *input, int output_fd)
6061

6162
if (ferror(infile)) {
6263
pr_err("lzma: read error: %s\n", strerror(errno));
63-
return -1;
64+
goto err_fclose;
6465
}
6566

6667
if (feof(infile))
@@ -74,7 +75,7 @@ int lzma_decompress_to_file(const char *input, int output_fd)
7475

7576
if (writen(output_fd, buf_out, write_size) != write_size) {
7677
pr_err("lzma: write error: %s\n", strerror(errno));
77-
return -1;
78+
goto err_fclose;
7879
}
7980

8081
strm.next_out = buf_out;
@@ -83,13 +84,15 @@ int lzma_decompress_to_file(const char *input, int output_fd)
8384

8485
if (ret != LZMA_OK) {
8586
if (ret == LZMA_STREAM_END)
86-
return 0;
87+
break;
8788

8889
pr_err("lzma: failed %s\n", lzma_strerror(ret));
89-
return -1;
90+
goto err_fclose;
9091
}
9192
}
9293

94+
err = 0;
95+
err_fclose:
9396
fclose(infile);
94-
return 0;
97+
return err;
9598
}

0 commit comments

Comments
 (0)