mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-11 20:21:11 +00:00
Fix a potential memory leak issue in wasm_native_init (#1465)
Should call `wasm_native_destroy` to destroy the registered native libs when registering native lib failed in `wasm_native_init`.
This commit is contained in:
parent
da79e3e9b2
commit
6820af6212
|
@ -362,24 +362,24 @@ wasm_native_init()
|
|||
#if WASM_ENABLE_LIBC_BUILTIN != 0
|
||||
n_native_symbols = get_libc_builtin_export_apis(&native_symbols);
|
||||
if (!wasm_native_register_natives("env", native_symbols, n_native_symbols))
|
||||
return false;
|
||||
goto fail;
|
||||
#endif /* WASM_ENABLE_LIBC_BUILTIN */
|
||||
|
||||
#if WASM_ENABLE_SPEC_TEST
|
||||
n_native_symbols = get_spectest_export_apis(&native_symbols);
|
||||
if (!wasm_native_register_natives("spectest", native_symbols,
|
||||
n_native_symbols))
|
||||
return false;
|
||||
goto fail;
|
||||
#endif /* WASM_ENABLE_SPEC_TEST */
|
||||
|
||||
#if WASM_ENABLE_LIBC_WASI != 0
|
||||
n_native_symbols = get_libc_wasi_export_apis(&native_symbols);
|
||||
if (!wasm_native_register_natives("wasi_unstable", native_symbols,
|
||||
n_native_symbols))
|
||||
return false;
|
||||
goto fail;
|
||||
if (!wasm_native_register_natives("wasi_snapshot_preview1", native_symbols,
|
||||
n_native_symbols))
|
||||
return false;
|
||||
goto fail;
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_BASE_LIB != 0
|
||||
|
@ -387,7 +387,7 @@ wasm_native_init()
|
|||
if (n_native_symbols > 0
|
||||
&& !wasm_native_register_natives("env", native_symbols,
|
||||
n_native_symbols))
|
||||
return false;
|
||||
goto fail;
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_APP_FRAMEWORK != 0
|
||||
|
@ -395,18 +395,18 @@ wasm_native_init()
|
|||
if (n_native_symbols > 0
|
||||
&& !wasm_native_register_natives("env", native_symbols,
|
||||
n_native_symbols))
|
||||
return false;
|
||||
goto fail;
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_LIB_PTHREAD != 0
|
||||
if (!lib_pthread_init())
|
||||
return false;
|
||||
goto fail;
|
||||
|
||||
n_native_symbols = get_lib_pthread_export_apis(&native_symbols);
|
||||
if (n_native_symbols > 0
|
||||
&& !wasm_native_register_natives("env", native_symbols,
|
||||
n_native_symbols))
|
||||
return false;
|
||||
goto fail;
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_LIBC_EMCC != 0
|
||||
|
@ -414,7 +414,7 @@ wasm_native_init()
|
|||
if (n_native_symbols > 0
|
||||
&& !wasm_native_register_natives("env", native_symbols,
|
||||
n_native_symbols))
|
||||
return false;
|
||||
goto fail;
|
||||
#endif /* WASM_ENABLE_LIBC_EMCC */
|
||||
|
||||
#if WASM_ENABLE_LIB_RATS != 0
|
||||
|
@ -422,10 +422,13 @@ wasm_native_init()
|
|||
if (n_native_symbols > 0
|
||||
&& !wasm_native_register_natives("env", native_symbols,
|
||||
n_native_symbols))
|
||||
return false;
|
||||
goto fail;
|
||||
#endif /* WASM_ENABLE_LIB_RATS */
|
||||
|
||||
return true;
|
||||
fail:
|
||||
wasm_native_destroy();
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -45,7 +45,7 @@ librats_verify_wrapper(wasm_exec_env_t exec_env, const char *evidence_json,
|
|||
/* clang-format off */
|
||||
#define REG_NATIVE_FUNC(func_name, signature) \
|
||||
{ #func_name, func_name##_wrapper, signature, NULL }
|
||||
/* clang-format off */
|
||||
/* clang-format on */
|
||||
|
||||
static NativeSymbol native_symbols_lib_rats[] = {
|
||||
REG_NATIVE_FUNC(librats_collect, "($)i"),
|
||||
|
|
Loading…
Reference in New Issue
Block a user