Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A M3Module maybe freed twice. #389

Open
YoungWenMing opened this issue Sep 30, 2022 · 0 comments · May be fixed by #390
Open

A M3Module maybe freed twice. #389

YoungWenMing opened this issue Sep 30, 2022 · 0 comments · May be fixed by #390

Comments

@YoungWenMing
Copy link

After a module is loaded to the runtime, we may get an error when handling module links. The loaded module has to be freed in such case, and thus another error may occur when the whole runtime is being freed: the module is freed before may be freed for the second time.
For example, somethings wrong happened after this statement in platforms/app/main.c:

    result = link_all (module);
    if (result) goto on_error;

    if (wasm_bins_qty < MAX_MODULES) {
        wasm_bins[wasm_bins_qty++] = wasm;
    }

    return result;

on_error:
    m3_FreeModule(module);
    if (wasm) free(wasm);
    if (f) fclose(f);

    return result;

and then m3_FreeModule is called.
However, at the end of the whole process, we do this:

    m3_FreeRuntime (runtime);
    m3_FreeEnvironment (env);

    return result ? 1 : 0;

The formerly freed module will be freed twice and thus make a segment fault occur.

YoungWenMing added a commit to YoungWenMing/wasm3 that referenced this issue Sep 30, 2022
A module maybe freed after it is loaded to the runtime and before
the runtime is released. Hence, it is necessary to remove the module
from the runtime's module list to avoid one module be freed twice.

Fix wasm3#389
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant