mirror of
https://github.com/libretro/mgba.git
synced 2024-11-23 16:10:01 +00:00
All: Fix several memory leaks
This commit is contained in:
parent
04f8597942
commit
a32cb5cc5e
1
CHANGES
1
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
|
||||
|
@ -90,6 +90,7 @@ void mCheatSetDeinit(struct mCheatSet* set) {
|
||||
if (set->name) {
|
||||
free(set->name);
|
||||
}
|
||||
StringListDeinit(&set->lines);
|
||||
set->deinit(set);
|
||||
free(set);
|
||||
}
|
||||
|
@ -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))
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ M_TEST_SUITE_TEARDOWN(GBMBC) {
|
||||
return 0;
|
||||
}
|
||||
struct mCore* core = *state;
|
||||
mCoreConfigDeinit(&core->config);
|
||||
core->deinit(core);
|
||||
return 0;
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ M_TEST_SUITE_TEARDOWN(GBMemory) {
|
||||
return 0;
|
||||
}
|
||||
struct mCore* core = *state;
|
||||
mCoreConfigDeinit(&core->config);
|
||||
core->deinit(core);
|
||||
return 0;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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))
|
||||
|
@ -562,6 +562,7 @@ void retro_unload_game(void) {
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
mCoreConfigDeinit(&core->config);
|
||||
core->deinit(core);
|
||||
mappedMemoryFree(data, dataSize);
|
||||
data = 0;
|
||||
|
@ -76,6 +76,7 @@
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
mCoreConfigDeinit(&core->config);
|
||||
core->deinit(core);
|
||||
[cheatSets release];
|
||||
free(outputBuffer);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -165,6 +165,7 @@ loadError:
|
||||
if (outputBuffer) {
|
||||
free(outputBuffer);
|
||||
}
|
||||
mCoreConfigDeinit(&core->config);
|
||||
core->deinit(core);
|
||||
|
||||
return !cleanExit;
|
||||
|
Loading…
Reference in New Issue
Block a user