Skip to content

Commit

Permalink
cr-restore: fix error handling and memory leak in read_vma
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
avagin authored and xemul committed Apr 5, 2013
1 parent c9c1ec7 commit 510b0da
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions cr-restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 510b0da

Please sign in to comment.