mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-30 13:58:34 +00:00
restore: Don't leak opened file descriptor in shmem_remap
Don't forget to close opened file in case of error. Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Acked-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
17
cr-restore.c
17
cr-restore.c
@@ -343,8 +343,7 @@ static int prepare_pipes_pid(int pid)
|
|||||||
static int shmem_remap(void *old_addr, void *new_addr, unsigned long size)
|
static int shmem_remap(void *old_addr, void *new_addr, unsigned long size)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
int fd;
|
int fd, ret = -1;
|
||||||
void *ret;
|
|
||||||
|
|
||||||
sprintf(path, "/proc/self/map_files/%lx-%lx",
|
sprintf(path, "/proc/self/map_files/%lx-%lx",
|
||||||
(long)old_addr, (long)old_addr + size);
|
(long)old_addr, (long)old_addr + size);
|
||||||
@@ -355,15 +354,17 @@ static int shmem_remap(void *old_addr, void *new_addr, unsigned long size)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = mmap(new_addr, size, PROT_READ | PROT_WRITE,
|
/* reuse old_addr variable */
|
||||||
MAP_SHARED | MAP_FIXED, fd, 0);
|
old_addr = mmap(new_addr, size, PROT_READ | PROT_WRITE,
|
||||||
if (ret != new_addr) {
|
MAP_SHARED | MAP_FIXED, fd, 0);
|
||||||
|
if (new_addr == old_addr)
|
||||||
|
ret = 0;
|
||||||
|
else
|
||||||
pr_perror("mmap failed");
|
pr_perror("mmap failed");
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return 0;
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int prepare_shared(int ps_fd)
|
static int prepare_shared(int ps_fd)
|
||||||
|
Reference in New Issue
Block a user