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

Audit use of "allocate" in js for correctness and memory leaks #34

Open
ewmailing opened this issue Aug 29, 2018 · 0 comments
Open

Audit use of "allocate" in js for correctness and memory leaks #34

ewmailing opened this issue Aug 29, 2018 · 0 comments

Comments

@ewmailing
Copy link
Owner

We currently have two instances of allocate() which allocate memory in JS and return to the C caller a c string:
iupemscripten_list.js: var c_str = allocate(intArrayFromString(ret_str), 'i8', ALLOC_NORMAL);
iupemscripten_text.js: var c_str = allocate(intArrayFromString(userText), 'i8', ALLOC_NORMAL);

The caller in C calls free() when it is done with this memory.

Potential problems:

  1. The Emscripten documentation now discourages use of allocate() directly and suggests use _malloc() instead.

  2. It is not clear if free() on the C-side actually and correctly frees memory created by allocate(). Perhaps a cleaner way to handle this is to callback into JavaScript passing back the pointer and calling _free().

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

No branches or pull requests

1 participant