[LibOS] Fix vma leak in shim_do_mmap when pal mapping fails

vma leaks when pal mapping (DkVirtualMemoryAlloc or fs_ops->mmap) fails.
Free vma correctly in such case.

Signed-off-by: Isaku Yamahata <isaku.yamahata@gmail.com>
This commit is contained in:
Isaku Yamahata
2019-02-05 17:12:13 +01:00
committed by Michał Kowalczyk
parent 000cc75944
commit 11ce277635
+8 -6
View File
@@ -110,19 +110,21 @@ void * shim_do_mmap (void * addr, size_t length, int prot, int flags, int fd,
void * cur_stack = current_stack();
assert(cur_stack < addr || cur_stack > addr + length);
/* addr needs to be kept for bkeep_munmap() below */
void * ret_addr = addr;
if (!hdl) {
addr = (void *) DkVirtualMemoryAlloc(addr, length, pal_alloc_type,
PAL_PROT(prot, 0));
ret_addr = (void *) DkVirtualMemoryAlloc(
ret_addr, length, pal_alloc_type, PAL_PROT(prot, 0));
if (!addr) {
if (!ret_addr) {
if (PAL_NATIVE_ERRNO == PAL_ERROR_DENIED)
ret = -EPERM;
else
ret = -PAL_ERRNO;
}
} else {
ret = hdl->fs->fs_ops->mmap(hdl, &addr, length, PAL_PROT(prot, flags),
flags, offset);
ret = hdl->fs->fs_ops->mmap(
hdl, &ret_addr, length, PAL_PROT(prot, flags), flags, offset);
}
if (hdl)
@@ -134,7 +136,7 @@ void * shim_do_mmap (void * addr, size_t length, int prot, int flags, int fd,
}
ADD_PROFILE_OCCURENCE(mmap, length);
return addr;
return ret_addr;
}
int shim_do_mprotect (void * addr, size_t length, int prot)