Commit ddcb61de authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Andrei Vagin

compel: Don't reclose files already closed

In case of error don't re-close files already closed.

https://github.com/xemul/criu/issues/148Reported-by: 's avatarAndrew Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Reviewed-by: 's avatarAndrey Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 2ac20e79
...@@ -73,12 +73,12 @@ static int piegen(void) ...@@ -73,12 +73,12 @@ static int piegen(void)
{ {
struct stat st; struct stat st;
void *mem; void *mem;
int fd; int fd, ret = -1;
fd = open(opts.input_filename, O_RDONLY); fd = open(opts.input_filename, O_RDONLY);
if (fd < 0) { if (fd < 0) {
pr_perror("Can't open file %s", opts.input_filename); pr_perror("Can't open file %s", opts.input_filename);
goto err; return -1;
} }
if (fstat(fd, &st)) { if (fstat(fd, &st)) {
...@@ -99,15 +99,21 @@ static int piegen(void) ...@@ -99,15 +99,21 @@ static int piegen(void)
} }
if (handle_elf(mem, st.st_size)) { if (handle_elf(mem, st.st_size)) {
fclose(fout); close(fd), fd = -1;
unlink(opts.output_filename); unlink(opts.output_filename);
goto err; goto err;
} }
ret = 0;
err: err:
if (fd >= 0)
close(fd);
if (fout)
fclose(fout); fclose(fout);
if (!ret)
printf("%s generated successfully.\n", opts.output_filename); printf("%s generated successfully.\n", opts.output_filename);
return 0; return ret;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment