Skip to content

Commit d1a94e4

Browse files
committed
Fix bug in the Wasm Exception error message memory handling
1 parent 3fea36d commit d1a94e4

File tree

4 files changed

+6
-22
lines changed

4 files changed

+6
-22
lines changed

lib/Runtime/Library/WasmLibrary.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Js
1313
{
1414
const unsigned int WasmLibrary::experimentalVersion = Wasm::experimentalVersion;
1515

16-
char16* lastWasmExceptionMessage = nullptr;
16+
char16* WasmLibrary::lastWasmExceptionMessage = nullptr;
1717

1818
Var WasmLibrary::instantiateModule(RecyclableObject* function, CallInfo callInfo, ...)
1919
{
@@ -168,9 +168,11 @@ namespace Js
168168
}
169169
#endif
170170
}
171-
catch (Wasm::WasmCompilationException ex)
171+
catch (Wasm::WasmCompilationException& ex)
172172
{
173-
Wasm::WasmCompilationException newEx(_u("function %s: %s"), body->GetDisplayName(), ex.GetErrorMessage());
173+
char16* originalMessage = ex.ReleaseErrorMessage();
174+
Wasm::WasmCompilationException newEx = Wasm::WasmCompilationException(_u("function %s: %s"), body->GetDisplayName(), originalMessage);
175+
SysFreeString(originalMessage);
174176
if (propagateError)
175177
{
176178
throw newEx;

lib/Runtime/Library/WasmLibrary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ namespace Js
4848
Js::Var ffi,
4949
Js::Var* start = nullptr
5050
);
51+
static char16* lastWasmExceptionMessage;
5152
#endif
5253
};
5354
}

lib/WasmReader/WasmByteCodeGenerator.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,14 +1477,6 @@ WasmCompilationException::FormatError(const char16* _msg, va_list arglist)
14771477
errorMsg = SysAllocString(buf);
14781478
}
14791479

1480-
WasmCompilationException::~WasmCompilationException()
1481-
{
1482-
if (errorMsg)
1483-
{
1484-
SysFreeString(errorMsg);
1485-
}
1486-
}
1487-
14881480
WasmCompilationException::WasmCompilationException(const char16* _msg, ...)
14891481
{
14901482
va_list arglist;

lib/WasmReader/WasmByteCodeGenerator.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,9 @@ namespace Wasm
4545
void FormatError(const char16* _msg, va_list arglist);
4646
char16* errorMsg;
4747
public:
48-
~WasmCompilationException();
4948
WasmCompilationException(const char16* _msg, ...);
5049
WasmCompilationException(const char16* _msg, va_list arglist);
5150

52-
void SetErrorMessage(char16* _errorMsg)
53-
{
54-
errorMsg = _errorMsg;
55-
}
56-
57-
const char16* GetErrorMessage() const
58-
{
59-
return errorMsg;
60-
}
61-
6251
char16* ReleaseErrorMessage()
6352
{
6453
Assert(errorMsg);

0 commit comments

Comments
 (0)