2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 22:05:36 +00:00

cr-restore: fix error handling and memory leak in read_vma

CID 996203 (#1 of 1): Resource leak (RESOURCE_LEAK)
15. leaked_storage: Variable "vma" going out of scope leaks the storage it points to.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Andrey Vagin
2013-04-05 01:44:32 +04:00
committed by Pavel Emelyanov
parent c9c1ec7b44
commit 510b0dacb4

View File

@@ -445,28 +445,33 @@ static int read_vmas(int pid)
break;
ret = pb_read_one_eof(fd, &e, PB_VMAS);
if (ret <= 0)
if (ret <= 0) {
xfree(vma);
break;
}
rst_vmas.nr++;
list_add_tail(&vma->list, &rst_vmas.h);
if (e->fd != -1) {
ret = -1;
pr_err("Error in vma->fd setting (%Ld)\n",
(unsigned long long)e->fd);
break;
}
vma->vma = *e;
vma_entry__free_unpacked(e, NULL);
if (vma->vma.fd != -1) {
ret = -1;
pr_err("Error in vma->fd setting (%Ld)\n",
(unsigned long long)vma->vma.fd);
break;
}
if (!vma_priv(&vma->vma))
continue;
priv_size += vma_area_len(vma);
}
if (ret < 0)
goto out;
/* Reserve a place for mapping private vma-s one by one */
addr = mmap(NULL, priv_size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
if (addr == MAP_FAILED) {