Skip to content

Commit 1b8ca02

Browse files
committed
Always free allocaed memory in mmunmap.
Without this change we were returning early from `__syscall_munmap` if `_munmap_js` failed. This could happen if `fd` was no longer a valid open file descriptor. However, even in this case we still want to go ahead and free any allocated memory. Fixes: emscripten-core#21360
1 parent a95c44e commit 1b8ca02

File tree

4 files changed

+1
-11
lines changed

4 files changed

+1
-11
lines changed

src/library_fs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,6 @@ FS.staticInit();` +
12761276
}
12771277
return stream.stream_ops.msync(stream, buffer, offset, length, mmapFlags);
12781278
},
1279-
munmap: (stream) => 0,
12801279
ioctl(stream, cmd, arg) {
12811280
if (!stream.stream_ops.ioctl) {
12821281
throw new FS.ErrnoError({{{ cDefs.ENOTTY }}});

src/library_noderawfs.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,6 @@ addToLibrary({
193193
// should we check if bytesWritten and length are the same?
194194
return 0;
195195
},
196-
munmap() {
197-
return 0;
198-
},
199196
ioctl() {
200197
throw new FS.ErrnoError({{{ cDefs.ENOTTY }}});
201198
}

src/library_syscall.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,10 @@ var SyscallsLibrary = {
159159
_munmap_js__i53abi: true,
160160
_munmap_js: (addr, len, prot, flags, fd, offset) => {
161161
#if FILESYSTEM && SYSCALLS_REQUIRE_FILESYSTEM
162-
if (isNaN(offset)) return {{{ cDefs.EOVERFLOW }}};
163162
var stream = SYSCALLS.getStreamFromFD(fd);
164163
if (prot & {{{ cDefs.PROT_WRITE }}}) {
165164
SYSCALLS.doMsync(addr, stream, len, flags, offset);
166165
}
167-
FS.munmap(stream);
168-
// implicitly return 0
169166
#endif
170167
},
171168

system/lib/libc/emscripten_mmap.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ int __syscall_munmap(intptr_t addr, size_t length) {
7373
UNLOCK(lock);
7474

7575
if (!(map->flags & MAP_ANONYMOUS)) {
76-
int rtn = _munmap_js(addr, length, map->prot, map->flags, map->fd, map->offset);
77-
if (rtn) {
78-
return rtn;
79-
}
76+
_munmap_js(addr, length, map->prot, map->flags, map->fd, map->offset);
8077
}
8178

8279
// Release the memory.

0 commit comments

Comments
 (0)