all repos — mgba @ a32cb5cc5e4fa0f1590725036ca58a490d0f1164

mGBA Game Boy Advance Emulator

All: Fix several memory leaks
Vicki Pfau vi@endrift.com
Mon, 22 Apr 2019 13:59:39 -0700
commit

a32cb5cc5e4fa0f1590725036ca58a490d0f1164

parent

04f85979423433b2f892abbce4c73fe984213f42

M CHANGESCHANGES

@@ -28,6 +28,7 @@ - CMake: Fix .deb imagemagick dependencies

- 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
M src/core/cheats.csrc/core/cheats.c

@@ -90,6 +90,7 @@ }

if (set->name) { free(set->name); } + StringListDeinit(&set->lines); set->deinit(set); free(set); }
M src/debugger/test/parser.csrc/debugger/test/parser.c

@@ -21,16 +21,16 @@ assert_false(adjusted > strlen(STR)); \

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 @@ assert_int_equal(tree->rhs->rhs->token.type, TOKEN_UINT_TYPE);

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))
M src/feature/gui/gui-runner.csrc/feature/gui/gui-runner.c

@@ -362,6 +362,7 @@ mInputMapInit(&runner->core->inputMap, &GBAInputInfo);

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 @@ mCoreConfigSave(&runner->config);

} mInputMapDeinit(&runner->core->inputMap); mLOG(GUI_RUNNER, DEBUG, "Deinitializing core..."); + mCoreConfigDeinit(&runner->core->config); runner->core->deinit(runner->core); runner->core = NULL;
M src/gb/test/core.csrc/gb/test/core.c

@@ -31,6 +31,7 @@ assert_non_null(core);

assert_true(core->init(core)); mCoreInitConfig(core, NULL); core->reset(core); + mCoreConfigDeinit(&core->config); core->deinit(core); }

@@ -41,6 +42,7 @@ assert_true(core->init(core));

mCoreInitConfig(core, NULL); assert_false(core->loadROM(core, NULL)); core->reset(core); + mCoreConfigDeinit(&core->config); core->deinit(core); }

@@ -51,7 +53,9 @@ assert_true(GBIsROM(vf));

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); }
M src/gb/test/mbc.csrc/gb/test/mbc.c

@@ -27,6 +27,7 @@ if (!*state) {

return 0; } struct mCore* core = *state; + mCoreConfigDeinit(&core->config); core->deinit(core); return 0; }
M src/gb/test/memory.csrc/gb/test/memory.c

@@ -27,6 +27,7 @@ if (!*state) {

return 0; } struct mCore* core = *state; + mCoreConfigDeinit(&core->config); core->deinit(core); return 0; }
M src/gb/test/rtc.csrc/gb/test/rtc.c

@@ -69,6 +69,7 @@ if (!*state) {

return 0; } struct GBRTCTest* test = *state; + mCoreConfigDeinit(&test->core->config); test->core->deinit(test->core); free(test); return 0;
M src/gba/test/cheats.csrc/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 @@ *state = core;

return 0; } -M_TEST_SUITE_TEARDOWN(GBACheats) { +static int cheatsTeardown(void** state) { if (!*state) { return 0; }

@@ -36,7 +36,7 @@ struct mCheatDevice* device = core->cheatDevice(core);

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 @@ assert_non_null(set);

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 @@ assert_int_equal(core->rawRead8(core, 0x03000000, -1), 0x78);

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 @@ assert_int_equal(core->rawRead8(core, 0x03000003, -1), 0);

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 @@ assert_int_equal(core->rawRead16(core, 0x03000006, -1), 0);

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 @@ assert_int_equal(core->rawRead16(core, 0x0300000C, -1), 0);

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 @@ 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(doPARv3If1x1) {

@@ -243,7 +243,7 @@ assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);

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 @@ 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), 0x21); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3If2x2) {

@@ -345,7 +345,7 @@ 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); assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3If2Contain1) {

@@ -392,7 +392,7 @@ mCheatRefresh(device, set);

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 @@ core->rawWrite8(core, 0x03000000, -1, 0x1);

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 @@ assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);

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 @@ mCheatRefresh(device, set);

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 @@ 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), 0x42); assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3IfXElsexXElse) {

@@ -668,7 +668,7 @@ 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); assert_int_equal(core->rawRead8(core, 0x03000006, -1), 0x62); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3IfXContain1) {

@@ -730,7 +730,7 @@ assert_int_equal(core->rawRead8(core, 0x03000001, -1), 0x1);

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 @@ 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); assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x52); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3IfXElseContain1) {

@@ -870,7 +870,7 @@ 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); assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x52); - set->deinit(set); + mCheatSetDeinit(set); } M_TEST_DEFINE(doPARv3IfXContain1ElseContain1) {

@@ -1016,7 +1016,7 @@ assert_int_equal(core->rawRead8(core, 0x03000005, -1), 0x51);

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 @@

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))
M src/platform/libretro/libretro.csrc/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;
M src/platform/openemu/mGBAGameCore.msrc/platform/openemu/mGBAGameCore.m

@@ -76,6 +76,7 @@ }

- (void)dealloc { + mCoreConfigDeinit(&core->config); core->deinit(core); [cheatSets release]; free(outputBuffer);
M src/platform/sdl/main.csrc/platform/sdl/main.c

@@ -143,6 +143,7 @@ renderer.filter = renderer.core->opts.resampleVideo;

if (!mSDLInit(&renderer)) { freeArguments(&args); + mCoreConfigDeinit(&renderer.core->config); renderer.core->deinit(renderer.core); return 1; }
M src/platform/test/fuzz-main.csrc/platform/test/fuzz-main.c

@@ -165,6 +165,7 @@ freeArguments(&args);

if (outputBuffer) { free(outputBuffer); } + mCoreConfigDeinit(&core->config); core->deinit(core); return !cleanExit;