diff --git a/include/mgba/script/types.h b/include/mgba/script/types.h index a771e42c0..faf4ca750 100644 --- a/include/mgba/script/types.h +++ b/include/mgba/script/types.h @@ -164,7 +164,8 @@ enum mScriptClassInitType { }; enum { - mSCRIPT_VALUE_FLAG_FREE_BUFFER = 1 + mSCRIPT_VALUE_FLAG_FREE_BUFFER = 1, + mSCRIPT_VALUE_FLAG_DEINIT = 2, }; struct mScriptType; diff --git a/src/script/types.c b/src/script/types.c index 7382d0411..34529a0df 100644 --- a/src/script/types.c +++ b/src/script/types.c @@ -1568,7 +1568,7 @@ void mScriptObjectFree(struct mScriptValue* value) { if (value->type->base != mSCRIPT_TYPE_OBJECT) { return; } - if (value->flags & mSCRIPT_VALUE_FLAG_FREE_BUFFER) { + if (value->flags & (mSCRIPT_VALUE_FLAG_DEINIT | mSCRIPT_VALUE_FLAG_FREE_BUFFER)) { mScriptClassInit(value->type->details.cls); if (value->type->details.cls->free) { struct mScriptValue deinitMember; @@ -1584,6 +1584,8 @@ void mScriptObjectFree(struct mScriptValue* value) { mScriptFrameDeinit(&frame); } } + } + if (value->flags & mSCRIPT_VALUE_FLAG_FREE_BUFFER) { free(value->value.opaque); } }