Commit 510b0dac authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

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: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent c9c1ec7b
......@@ -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) {
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)e->fd);
(unsigned long long)vma->vma.fd);
break;
}
vma->vma = *e;
vma_entry__free_unpacked(e, NULL);
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) {
......
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