Lookup pinvoke_names in wasm_dl_load first
[mono-project.git] / sdks / builds / fix-emscripten-8511.patch
blobdd14a8c3ed0cb794199c179a4aba9125f118d84a
1 From d8a94684e2a9a584080757a324c4c42183f6d11a Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Laban?= <jerome.laban@nventive.com>
3 Date: Mon, 29 Apr 2019 11:54:21 -0400
4 Subject: [PATCH] Invalid double dlopen failure fix
6 Fixes #8511
7 ---
8 src/support.js | 27 ++++++++++++++++++++++-----
9 tests/test_browser.py | 10 ++++++++++
10 2 files changed, 32 insertions(+), 5 deletions(-)
12 diff --git a/src/support.js b/src/support.js
13 index 68360e406..419e4cbb5 100644
14 --- a/src/support.js
15 +++ b/src/support.js
16 @@ -302,14 +302,31 @@ function loadDynamicLibrary(lib, flags) {
17 dso.module = libModule;
20 + function cleanupOnError() {
21 + var lib_record = LDSO.loadedLibs[handle];
22 + delete LDSO.loadedLibNames[lib_record.name];
23 + delete LDSO.loadedLibs[handle];
24 + }
26 if (flags.loadAsync) {
27 - return getLibModule().then(function(libModule) {
28 - moduleLoaded(libModule);
29 - return handle;
30 - })
31 + return getLibModule()
32 + .catch(function (e) {
33 + cleanupOnError();
34 + throw e;
35 + })
36 + .then(function (libModule) {
37 + moduleLoaded(libModule);
38 + return handle;
39 + })
42 - moduleLoaded(getLibModule());
43 + try {
44 + moduleLoaded(getLibModule());
45 + }
46 + catch (e) {
47 + cleanupOnError();
48 + throw e;
49 + }
50 return handle;
53 diff --git a/tests/test_browser.py b/tests/test_browser.py
54 index 7836141db..eeb7ad2ff 100644
55 --- a/tests/test_browser.py
56 +++ b/tests/test_browser.py
57 @@ -2408,6 +2408,16 @@ void *getBindBuffer() {
58 REPORT_RESULT(3);
59 return 3;
61 + void *invalid_handle = dlopen("/invalid.so", 0);
62 + if (invalid_handle) {
63 + REPORT_RESULT(4);
64 + return 4;
65 + }
66 + void *invalid_handle2 = dlopen("/invalid.so", 0);
67 + if (invalid_handle2) {
68 + REPORT_RESULT(5);
69 + return 5;
70 + }
71 REPORT_RESULT(0);
72 return 0;
74 --
75 2.17.1.windows.2