From 85234cb540c2b2863dfea6c20496dcb451df8889 Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Tue, 1 Sep 2020 15:55:58 -0700 Subject: Fix ExceptionPackage memory errors (#3088) First, adds an explicit destructor call to fix a memory leak in `Literal::operator=` in which existing `ExceptionPackage`s would be silently dropped. Next, changes `Literal::getExceptionPackage` to return the `ExceptionPackage` by value to avoid a use-after-free bug in the interpreter that was surfaced by the new destructor call. A future improvement would be to switch to using `std::variant`. Fixes #3087. --- src/literal.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/literal.h') diff --git a/src/literal.h b/src/literal.h index 5c72bf96c..cffa9ab7d 100644 --- a/src/literal.h +++ b/src/literal.h @@ -135,10 +135,7 @@ public: assert(type == Type::funcref); return func; } - const ExceptionPackage& getExceptionPackage() const { - assert(type == Type::exnref); - return *exn.get(); - } + ExceptionPackage getExceptionPackage() const; // careful! int32_t* geti32Ptr() { -- cgit v1.2.3