Skip to content

Commit

Permalink
fix: Function environment is correctly released
Browse files Browse the repository at this point in the history
  • Loading branch information
jubianchi committed Feb 1, 2021
1 parent 52bbf1c commit b6f8dc3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
Binary file modified lib/libwasmer.dylib
Binary file not shown.
4 changes: 3 additions & 1 deletion src/api/objects/func.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,16 @@ void func_env_finalizer(void *env) {
if (fenv->fcc.function_handler->common.fn_flags & ZEND_ACC_CLOSURE) {
OBJ_RELEASE(ZEND_CLOSURE_OBJECT(fenv->fcc.function_handler));
}

efree(env);
}

PHP_FUNCTION (wasm_func_new) {
zval *store_val;
zval *functype_val;
zend_fcall_info fci;
// TODO: Env finalizer has some problem, we have to use malloc instead of emalloc. Fix that.
wasmer_func_env *env = malloc(sizeof(wasmer_func_env));
wasmer_func_env *env = emalloc(sizeof(wasmer_func_env));

ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 3, 3)
Z_PARAM_RESOURCE(store_val)
Expand Down
6 changes: 1 addition & 5 deletions src/wasmer.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ WASMER_VEC_CLASS_DECLARE_WITH_ALIAS(extern, xtern)
WASMER_RESOURCE_DECLARE(foreign)
WASMER_RESOURCE_DECLARE(frame)
WASMER_VEC_CLASS_DECLARE(frame)
WASMER_RESOURCE_DECLARE_WITHOUT_DTOR(func)
static ZEND_RSRC_DTOR_FUNC(wasm_func_dtor) {
// TODO: If we call wasm_func_delete here, the function environment gets freed two times which is incorrect. Fix that.
efree(res->ptr);
}
WASMER_RESOURCE_DECLARE(func)
WASMER_RESOURCE_DECLARE(global)
WASMER_RESOURCE_DECLARE(instance)
WASMER_RESOURCE_DECLARE(memory)
Expand Down

0 comments on commit b6f8dc3

Please sign in to comment.