diff --git a/CHANGES b/CHANGES index 35422cef7..d20924cce 100644 --- a/CHANGES +++ b/CHANGES @@ -28,6 +28,7 @@ Other fixes: - Qt: Fix crash in sprite viewer magnification (fixes mgba.io/i/1362) - 3DS: Ensure core 2 can be used for threaded renderer (fixes mgba.io/i/1371) - GB Core: Fix toggling WIN and OBJ being swapped + - All: Fix several memory leaks Misc: - GBA Savedata: EEPROM performance fixes - GBA Savedata: Automatically map 1Mbit Flash files as 1Mbit Flash diff --git a/src/core/cheats.c b/src/core/cheats.c index d0ed72508..0abcbd537 100644 --- a/src/core/cheats.c +++ b/src/core/cheats.c @@ -90,6 +90,7 @@ void mCheatSetDeinit(struct mCheatSet* set) { if (set->name) { free(set->name); } + StringListDeinit(&set->lines); set->deinit(set); free(set); } diff --git a/src/debugger/test/parser.c b/src/debugger/test/parser.c index a2635f4fb..c1c2840d2 100644 --- a/src/debugger/test/parser.c +++ b/src/debugger/test/parser.c @@ -21,16 +21,16 @@ struct LPTest { struct ParseTree* tree = &lp->tree; \ parseLexedExpression(tree, &lp->lv) -M_TEST_SUITE_SETUP(Parser) { +static int parseSetup(void** state) { struct LPTest* lp = malloc(sizeof(struct LPTest)); LexVectorInit(&lp->lv, 0); *state = lp; return 0; } -M_TEST_SUITE_TEARDOWN(Parser) { +static int parseTeardown(void** state) { struct LPTest* lp = *state; - parseFree(&lp->tree); \ + parseFree(&lp->tree); lexFree(&lp->lv); LexVectorDeinit(&lp->lv); free(lp); @@ -135,14 +135,14 @@ M_TEST_DEFINE(parseUnaryChainedOperator) { assert_int_equal(tree->rhs->rhs->token.uintValue, 2); } -M_TEST_SUITE_DEFINE_SETUP_TEARDOWN(Parser, - cmocka_unit_test(parseEmpty), - cmocka_unit_test(parseInt), - cmocka_unit_test(parseLexError), - cmocka_unit_test(parseError), - cmocka_unit_test(parseSimpleExpression), - cmocka_unit_test(parseAddMultplyExpression), - cmocka_unit_test(parseParentheticalExpression), - cmocka_unit_test(parseParentheticalAddMultplyExpression), - cmocka_unit_test(parseIsolatedOperator), - cmocka_unit_test(parseUnaryChainedOperator)) +M_TEST_SUITE_DEFINE(Parser, + cmocka_unit_test_setup_teardown(parseEmpty, parseSetup, parseTeardown), + cmocka_unit_test_setup_teardown(parseInt, parseSetup, parseTeardown), + cmocka_unit_test_setup_teardown(parseLexError, parseSetup, parseTeardown), + cmocka_unit_test_setup_teardown(parseError, parseSetup, parseTeardown), + cmocka_unit_test_setup_teardown(parseSimpleExpression, parseSetup, parseTeardown), + cmocka_unit_test_setup_teardown(parseAddMultplyExpression, parseSetup, parseTeardown), + cmocka_unit_test_setup_teardown(parseParentheticalExpression, parseSetup, parseTeardown), + cmocka_unit_test_setup_teardown(parseParentheticalAddMultplyExpression, parseSetup, parseTeardown), + cmocka_unit_test_setup_teardown(parseIsolatedOperator, parseSetup, parseTeardown), + cmocka_unit_test_setup_teardown(parseUnaryChainedOperator, parseSetup, parseTeardown)) diff --git a/src/feature/gui/gui-runner.c b/src/feature/gui/gui-runner.c index 50c9dea42..128160cad 100644 --- a/src/feature/gui/gui-runner.c +++ b/src/feature/gui/gui-runner.c @@ -362,6 +362,7 @@ void mGUIRun(struct mGUIRunner* runner, const char* path) { found = mCoreLoadFile(runner->core, path); if (!found) { mLOG(GUI_RUNNER, WARN, "Failed to load %s!", path); + mCoreConfigDeinit(&runner->core->config); runner->core->deinit(runner->core); } } @@ -606,6 +607,7 @@ void mGUIRun(struct mGUIRunner* runner, const char* path) { } mInputMapDeinit(&runner->core->inputMap); mLOG(GUI_RUNNER, DEBUG, "Deinitializing core..."); + mCoreConfigDeinit(&runner->core->config); runner->core->deinit(runner->core); runner->core = NULL; diff --git a/src/gb/test/core.c b/src/gb/test/core.c index a8638012b..1d0b3416a 100644 --- a/src/gb/test/core.c +++ b/src/gb/test/core.c @@ -31,6 +31,7 @@ M_TEST_DEFINE(reset) { assert_true(core->init(core)); mCoreInitConfig(core, NULL); core->reset(core); + mCoreConfigDeinit(&core->config); core->deinit(core); } @@ -41,6 +42,7 @@ M_TEST_DEFINE(loadNullROM) { mCoreInitConfig(core, NULL); assert_false(core->loadROM(core, NULL)); core->reset(core); + mCoreConfigDeinit(&core->config); core->deinit(core); } @@ -51,7 +53,9 @@ M_TEST_DEFINE(isROM) { struct mCore* core = mCoreFindVF(vf); assert_non_null(core); assert_int_equal(core->platform(core), PLATFORM_GB); + vf->close(vf); assert_true(core->init(core)); + core->deinit(core); } diff --git a/src/gb/test/mbc.c b/src/gb/test/mbc.c index 5498d004d..7bcfcd248 100644 --- a/src/gb/test/mbc.c +++ b/src/gb/test/mbc.c @@ -27,6 +27,7 @@ M_TEST_SUITE_TEARDOWN(GBMBC) { return 0; } struct mCore* core = *state; + mCoreConfigDeinit(&core->config); core->deinit(core); return 0; } diff --git a/src/gb/test/memory.c b/src/gb/test/memory.c index 01a4b398f..ab64598ff 100644 --- a/src/gb/test/memory.c +++ b/src/gb/test/memory.c @@ -27,6 +27,7 @@ M_TEST_SUITE_TEARDOWN(GBMemory) { return 0; } struct mCore* core = *state; + mCoreConfigDeinit(&core->config); core->deinit(core); return 0; } diff --git a/src/gb/test/rtc.c b/src/gb/test/rtc.c index 71d06ced2..6ac03feb5 100644 --- a/src/gb/test/rtc.c +++ b/src/gb/test/rtc.c @@ -69,6 +69,7 @@ M_TEST_SUITE_TEARDOWN(GBRTC) { return 0; } struct GBRTCTest* test = *state; + mCoreConfigDeinit(&test->core->config); test->core->deinit(test->core); free(test); return 0; diff --git a/src/gba/test/cheats.c b/src/gba/test/cheats.c index a18e77c5e..6f4b8cb4c 100644 --- a/src/gba/test/cheats.c +++ b/src/gba/test/cheats.c @@ -13,7 +13,7 @@ #include "gba/cheats/parv3.h" #include "gba/cheats/gameshark.h" -M_TEST_SUITE_SETUP(GBACheats) { +static int cheatsSetup(void** state) { struct mCore* core = GBACoreCreate(); core->init(core); core->cheatDevice(core); @@ -21,7 +21,7 @@ M_TEST_SUITE_SETUP(GBACheats) { return 0; } -M_TEST_SUITE_TEARDOWN(GBACheats) { +static int cheatsTeardown(void** state) { if (!*state) { return 0; } @@ -36,7 +36,7 @@ M_TEST_DEFINE(createSet) { assert_non_null(device); struct mCheatSet* set = device->createSet(device, NULL); assert_non_null(set); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(addRawPARv3) { @@ -48,7 +48,7 @@ M_TEST_DEFINE(addRawPARv3) { GBACheatSetGameSharkVersion((struct GBACheatSet*) set, GBA_GS_PARV3_RAW); assert_true(set->addLine(set, "80000000 00000000", GBA_CHEAT_PRO_ACTION_REPLAY)); assert_false(set->addLine(set, "43000000 00000000", GBA_CHEAT_PRO_ACTION_REPLAY)); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3Assign) { @@ -72,7 +72,7 @@ M_TEST_DEFINE(doPARv3Assign) { assert_int_equal(core->rawRead16(core, 0x03000002, -1), 0x5678); assert_int_equal(core->rawRead32(core, 0x03000004, -1), 0x12345678); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3Slide1) { @@ -101,7 +101,7 @@ M_TEST_DEFINE(doPARv3Slide1) { assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0); assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3Slide2) { @@ -130,7 +130,7 @@ M_TEST_DEFINE(doPARv3Slide2) { assert_int_equal(core->rawRead16(core, 0x03000008, -1), 0); assert_int_equal(core->rawRead16(core, 0x0300000A, -1), 0); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3Slide4) { @@ -159,7 +159,7 @@ M_TEST_DEFINE(doPARv3Slide4) { assert_int_equal(core->rawRead16(core, 0x03000010, -1), 0); assert_int_equal(core->rawRead16(core, 0x03000014, -1), 0); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3If1) { @@ -188,7 +188,7 @@ M_TEST_DEFINE(doPARv3If1) { assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1); assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x11); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3If1x1) { @@ -243,7 +243,7 @@ M_TEST_DEFINE(doPARv3If1x1) { assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21); assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3If2) { @@ -277,7 +277,7 @@ M_TEST_DEFINE(doPARv3If2) { assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x11); assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3If2x2) { @@ -345,7 +345,7 @@ M_TEST_DEFINE(doPARv3If2x2) { assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31); assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41); assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3If2Contain1) { @@ -392,7 +392,7 @@ M_TEST_DEFINE(doPARv3If2Contain1) { assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1); assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1); assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3IfX) { @@ -421,7 +421,7 @@ M_TEST_DEFINE(doPARv3IfX) { mCheatRefresh(device, set); assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1); assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x11); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3IfXxX) { @@ -484,7 +484,7 @@ M_TEST_DEFINE(doPARv3IfXxX) { assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21); assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32); assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3IfXElse) { @@ -519,7 +519,7 @@ M_TEST_DEFINE(doPARv3IfXElse) { assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x1); assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x11); assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x22); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3IfXElsexX) { @@ -590,7 +590,7 @@ M_TEST_DEFINE(doPARv3IfXElsexX) { assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32); assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42); assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3IfXElsexXElse) { @@ -668,7 +668,7 @@ M_TEST_DEFINE(doPARv3IfXElsexXElse) { assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x42); assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51); assert_int_equal(core->rawRead8(core, 0x03000006, -1), 0x62); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3IfXContain1) { @@ -730,7 +730,7 @@ M_TEST_DEFINE(doPARv3IfXContain1) { assert_int_equal(core->rawRead8(core, 0x03000002, -1), 0x21); assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31); assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3IfXContain1Else) { @@ -800,7 +800,7 @@ M_TEST_DEFINE(doPARv3IfXContain1Else) { assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x31); assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41); assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x52); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3IfXElseContain1) { @@ -870,7 +870,7 @@ M_TEST_DEFINE(doPARv3IfXElseContain1) { assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0x32); assert_int_equal(core->rawRead8(core, 0x03000004, -1), 0x41); assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x52); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3IfXContain1ElseContain1) { @@ -1016,7 +1016,7 @@ M_TEST_DEFINE(doPARv3IfXContain1ElseContain1) { assert_int_equal(core->rawRead8(core, 0x03000006, -1), 0x62); assert_int_equal(core->rawRead8(core, 0x03000007, -1), 0x71); assert_int_equal(core->rawRead8(core, 0x03000008, -1), 0x82); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3IfButton) { @@ -1046,28 +1046,28 @@ M_TEST_DEFINE(doPARv3IfButton) { core->rawWrite8(core, 0x03000000, -1, 0); mCheatRefresh(device, set); assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0); - set->deinit(set); + mCheatSetDeinit(set); } -M_TEST_SUITE_DEFINE_SETUP_TEARDOWN(GBACheats, - cmocka_unit_test(createSet), - cmocka_unit_test(addRawPARv3), - cmocka_unit_test(doPARv3Assign), - cmocka_unit_test(doPARv3Slide1), - cmocka_unit_test(doPARv3Slide2), - cmocka_unit_test(doPARv3Slide4), - cmocka_unit_test(doPARv3If1), - cmocka_unit_test(doPARv3If1x1), - cmocka_unit_test(doPARv3If2), - cmocka_unit_test(doPARv3If2x2), - cmocka_unit_test(doPARv3If2Contain1), - cmocka_unit_test(doPARv3IfX), - cmocka_unit_test(doPARv3IfXxX), - cmocka_unit_test(doPARv3IfXElse), - cmocka_unit_test(doPARv3IfXElsexX), - cmocka_unit_test(doPARv3IfXElsexXElse), - cmocka_unit_test(doPARv3IfXContain1), - cmocka_unit_test(doPARv3IfXContain1Else), - cmocka_unit_test(doPARv3IfXElseContain1), - cmocka_unit_test(doPARv3IfXContain1ElseContain1), - cmocka_unit_test(doPARv3IfButton)) +M_TEST_SUITE_DEFINE(GBACheats, + cmocka_unit_test_setup_teardown(createSet, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(addRawPARv3, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3Assign, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3Slide1, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3Slide2, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3Slide4, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3If1, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3If1x1, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3If2, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3If2x2, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3If2Contain1, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3IfX, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3IfXxX, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3IfXElse, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3IfXElsexX, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3IfXElsexXElse, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3IfXContain1, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3IfXContain1Else, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3IfXElseContain1, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3IfXContain1ElseContain1, cheatsSetup, cheatsTeardown), + cmocka_unit_test_setup_teardown(doPARv3IfButton, cheatsSetup, cheatsTeardown)) diff --git a/src/platform/libretro/libretro.c b/src/platform/libretro/libretro.c index 6caa5d866..29dbc9033 100644 --- a/src/platform/libretro/libretro.c +++ b/src/platform/libretro/libretro.c @@ -562,6 +562,7 @@ void retro_unload_game(void) { if (!core) { return; } + mCoreConfigDeinit(&core->config); core->deinit(core); mappedMemoryFree(data, dataSize); data = 0; diff --git a/src/platform/openemu/mGBAGameCore.m b/src/platform/openemu/mGBAGameCore.m index 9b2b93b05..2612ddef4 100644 --- a/src/platform/openemu/mGBAGameCore.m +++ b/src/platform/openemu/mGBAGameCore.m @@ -76,6 +76,7 @@ - (void)dealloc { + mCoreConfigDeinit(&core->config); core->deinit(core); [cheatSets release]; free(outputBuffer); diff --git a/src/platform/sdl/main.c b/src/platform/sdl/main.c index 0da0698b9..450e1868a 100644 --- a/src/platform/sdl/main.c +++ b/src/platform/sdl/main.c @@ -143,6 +143,7 @@ int main(int argc, char** argv) { if (!mSDLInit(&renderer)) { freeArguments(&args); + mCoreConfigDeinit(&renderer.core->config); renderer.core->deinit(renderer.core); return 1; } diff --git a/src/platform/test/fuzz-main.c b/src/platform/test/fuzz-main.c index 044450099..b167a1443 100644 --- a/src/platform/test/fuzz-main.c +++ b/src/platform/test/fuzz-main.c @@ -165,6 +165,7 @@ loadError: if (outputBuffer) { free(outputBuffer); } + mCoreConfigDeinit(&core->config); core->deinit(core); return !cleanExit;