ewmailing / IupEmscripten

Emscripten (native web browser) backend for IUP (Portable native-GUI Interface) [switch to Emscripten branch]
Other
10 stars 1 forks source link

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

Open ewmailing opened 6 years ago

ewmailing commented 6 years ago

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().