diff options
author | Ian Moffett <ian@osmora.org> | 2024-04-25 01:05:05 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-04-25 01:05:05 -0400 |
commit | 0b38202bc82d4a417fe9fd689ac99f986efb0732 (patch) | |
tree | 91136a63cb66037445296009ec308b098f4dfb94 /sys/vm | |
parent | 80093ab214bc339c4cb4f7e1a4fb79032c09bfa8 (diff) |
kernel: vm_map: Cleanup on failure in mmap()
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/vm')
-rw-r--r-- | sys/vm/vm_map.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 5d40d29..f338f4f 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -340,7 +340,7 @@ mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off) if (__TEST(flags, MAP_ANONYMOUS)) { /* Try to create a virtual memory object */ if (vm_obj_init(&vmobj, NULL) != 0) - return 0; + goto fail; /* * If 'addr' is NULL, we'll just allocate physical @@ -371,16 +371,15 @@ mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off) /* Did this work? */ if (physmem == 0 && addr == NULL) { - return MAP_FAILED; + goto fail; } } else if (__TEST(flags, MAP_SHARED)) { physmem = vm_fd_map(addr, prot, len, off, fildes, mapping); if (physmem == 0) { - return MAP_FAILED; + goto fail; } } - map_start = __ALIGN_DOWN((vaddr_t)addr, GRANULE); map_end = map_start + __ALIGN_UP(len + misalign, GRANULE); @@ -393,6 +392,9 @@ mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off) vm_mapspace_insert(&td->mapspace, mapping); spinlock_release(&td->mapspace_lock); return (void *)addr; +fail: + DESTROY_MAPPING(mapping); + return MAP_FAILED; } /* |