You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MUNMAP leaks the memory if file descriptor is closed #21360
I noticed a memory leak using Skia's SkStream::MakeFromFile with EMSDK caused by the inability to release the allocated memory when a file descriptor is not valid (even for MAP_PRIVATE mode).
static sk_sp<SkData> mmap_filename(const char path[]) {
FILE* file = sk_fopen(path, kRead_SkFILE_Flag);
if (nullptr == file) {
return nullptr;
}
auto data = SkData::MakeFromFILE(file); // <--- this calls sk_fmmap and remembers the memory
sk_fclose(file); // <--- this releases the file handle, mmaped buffer in `data` won't be released
return data;
}
The munmap() function shall remove any mappings for those entire pages containing any part of the address space of the process starting at addr and continuing for len bytes.
So we should be safe to release the addr pointer when stream is closed in munmap_js, something like:
var stream = FS.getStream(fd);
if (!stream) {
_free(addr);
} else {
...
}
Activity
Always free allocaed memory in mmunmap.
Always free allocaed memory in mmunmap.
sbc100 commentedon Feb 16, 2024
Fix is in #21363
nightelf3 commentedon Feb 16, 2024
Wow, thank you a lot!
Always free allocaed memory in mmunmap. (#21363)
Always free allocaed memory in mmunmap. (emscripten-core#21363)
Merge upstream 3.1.56 (#64)