wasmer: Memory leak when using Rayon
The attached code, when I compile it, outputs:
> LD_LIBRARY_PATH=/usr/local/lib ./check_leaks
root 14599 0.0 0.0 27600 1916 pts/0 S+ 19:25 0:00 ./check_leaks
root 14600 0.0 0.0 113288 1204 pts/0 S+ 19:25 0:00 sh -c ps aux | grep check_leaks
root 14602 0.0 0.0 112816 964 pts/0 S+ 19:25 0:00 grep check_leaks
===============================
root 14599 373 0.4 310360 18316 pts/0 Sl+ 19:25 0:22 ./check_leaks
root 14607 0.0 0.0 113288 1204 pts/0 S+ 19:25 0:00 sh -c ps aux | grep check_leaks
root 14609 0.0 0.0 112816 960 pts/0 S+ 19:25 0:00 grep check_leaks
This looks problematic … ?
Here is the code in question:
// gcc --std=c99 -L/usr/local/lib check_leaks.c -o check_leaks -lwasmer
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <wasmer.h>
wasm_byte_vec_t slurp (const char *path) {
FILE* file = fopen(path, "rb");
if (NULL == file) {
perror("fopen");
exit(1);
}
fseek(file, 0L, SEEK_END);
size_t file_size = ftell(file);
fseek(file, 0L, SEEK_SET);
wasm_byte_vec_t binary;
wasm_byte_vec_new_uninitialized(&binary, file_size);
if (fread(binary.data, file_size, 1, file) != 1) {
perror("> Error loading module!\n");
exit(1);
}
fclose(file);
return binary;
}
int main(int argc, char *argv[]) {
assert(argc == 2);
const char* path = argv[1];
unsigned i;
wasm_engine_t* engine = wasm_engine_new();
wasm_store_t* store = wasm_store_new(engine);
wasm_byte_vec_t wasm = slurp(path);
system("ps aux | grep check_leaks");
fprintf(stdout, "===============================\n");
for (i=0; i<100; i++) {
wasm_module_t* module = wasm_module_new(store, &wasm);
if (NULL == module) {
fprintf(stderr, "bad module?");
exit(1);
}
wasm_module_delete(module);
}
wasm_byte_vec_delete(&wasm);
system("ps aux | grep check_leaks");
wasm_store_delete(store);
wasm_engine_delete(engine);
return 0;
}
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (16 by maintainers)
@chenyukang
Please, read https://github.com/wasmerio/wasmer/blob/master/lib/c-api/src/wasm_c_api/DEVELOPMENT.md#destructors 😃.
I would like to tackle it. 😃