diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-05-12 10:51:12 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-05-12 10:51:12 -0700 |
commit | af721247c243951f544a1843954b3ea958d65c76 (patch) | |
tree | d92d989be980e38d24b7198059455f3ea2aaae23 | |
parent | 5d22fa213f7ec66426e2a838b07a38802714dcef (diff) |
fix file argument changing before callback in async_wget; fixes #2349
-rw-r--r-- | src/library_browser.js | 17 | ||||
-rw-r--r-- | tests/emscripten_fs_api_browser.cpp | 5 |
2 files changed, 18 insertions, 4 deletions
diff --git a/src/library_browser.js b/src/library_browser.js index 44e8c473..57fe1f9f 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -688,15 +688,22 @@ mergeInto(LibraryManager.library, { emscripten_async_wget: function(url, file, onload, onerror) { var _url = Pointer_stringify(url); var _file = Pointer_stringify(file); + function doCallback(callback) { + if (callback) { + var stack = Runtime.stackSave(); + Runtime.dynCall('vi', callback, [allocate(intArrayFromString(_file), 'i8', ALLOC_STACK)]); + Runtime.stackRestore(stack); + } + } FS.createPreloadedFile( PATH.dirname(_file), PATH.basename(_file), _url, true, true, function() { - if (onload) Runtime.dynCall('vi', onload, [file]); + doCallback(onload); }, function() { - if (onerror) Runtime.dynCall('vi', onerror, [file]); + doCallback(onerror); } ); }, @@ -727,7 +734,11 @@ mergeInto(LibraryManager.library, { http.onload = function http_onload(e) { if (http.status == 200) { FS.createDataFile( _file.substr(0, index), _file.substr(index + 1), new Uint8Array(http.response), true, true); - if (onload) Runtime.dynCall('vii', onload, [arg, file]); + if (onload) { + var stack = Runtime.stackSave(); + Runtime.dynCall('vii', onload, [arg, allocate(intArrayFromString(_file), 'i8', ALLOC_STACK)]); + Runtime.stackRestore(stack); + } } else { if (onerror) Runtime.dynCall('vii', onerror, [arg, http.status]); } diff --git a/tests/emscripten_fs_api_browser.cpp b/tests/emscripten_fs_api_browser.cpp index 0355287a..1410ba3c 100644 --- a/tests/emscripten_fs_api_browser.cpp +++ b/tests/emscripten_fs_api_browser.cpp @@ -107,11 +107,14 @@ int main() { onLoaded, onError); + char name[40]; + strcpy(name, "/tmp/screen_shot.png"); // test for issue #2349, name being free'd emscripten_async_wget( "http://localhost:8888/screenshot.png", - "/tmp/screen_shot.png", + name, onLoaded, onError); + memset(name, 0, 30); emscripten_set_main_loop(wait_wgets, 0, 0); |