Skip to content

Commit

Permalink
files-reg: don't forget to close fd in case of error
Browse files Browse the repository at this point in the history
CID 996201 (#1 of 1): Resource leak (RESOURCE_LEAK)
9. leaked_handle: Handle variable "fd" going out of scope leaks the handle.

CID 996202 (#1 of 1): Resource leak (RESOURCE_LEAK)
6. leaked_handle: Handle variable "fd" going out of scope leaks the handle.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
  • Loading branch information
avagin authored and xemul committed Apr 5, 2013
1 parent 510b0da commit c518d47
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions files-reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ static int dump_ghost_file(int _fd, u32 id, const struct stat *st)
return -1;

if (S_ISREG(st->st_mode)) {
int fd;
int fd, ret;

/*
* Reopen file locally since it may have no read
Expand All @@ -243,10 +243,10 @@ static int dump_ghost_file(int _fd, u32 id, const struct stat *st)
pr_perror("Can't open ghost original file");
return -1;
}
if (copy_file(fd, img, st->st_size))
return -1;

ret = copy_file(fd, img, st->st_size);
close(fd);
if (ret)
return -1;
}

close(img);
Expand Down Expand Up @@ -538,6 +538,7 @@ static int do_open_reg(struct reg_file_info *rfi, void *arg)

if (lseek(fd, rfi->rfe->pos, SEEK_SET) < 0) {
pr_perror("Can't restore file pos");
close(fd);
return -1;
}

Expand Down

0 comments on commit c518d47

Please sign in to comment.