Conditional frees

This commit is contained in:
twinaphex 2017-11-17 19:52:15 +01:00
parent 1aa05de8ba
commit 56a3bc10e3

View File

@ -915,6 +915,7 @@ static int cheevos_parse_condition(cheevos_condition_t *condition, const char* m
{ {
while (--condset >= condition->condsets) while (--condset >= condition->condsets)
{ {
if ((void*)condset->conds)
free((void*)condset->conds); free((void*)condset->conds);
} }
@ -937,8 +938,12 @@ static void cheevos_free_condition(cheevos_condition_t* condition)
if (condition->condsets) if (condition->condsets)
{ {
for (i = 0; i < condition->count; i++) for (i = 0; i < condition->count; i++)
{
if ((void*)condition->condsets[i].conds)
free((void*)condition->condsets[i].conds); free((void*)condition->condsets[i].conds);
}
if ((void*)condition->condsets)
free((void*)condition->condsets); free((void*)condition->condsets);
} }
} }
@ -996,6 +1001,7 @@ static int cheevos_parse_expression(cheevos_expr_t *expr, const char* mem)
/* invalid character in expression */ /* invalid character in expression */
else else
{ {
if ((void*)expr->terms)
free((void*)expr->terms); free((void*)expr->terms);
return -1; return -1;
} }
@ -1072,6 +1078,7 @@ error:
cheevos_free_condition(&lb->start); cheevos_free_condition(&lb->start);
cheevos_free_condition(&lb->cancel); cheevos_free_condition(&lb->cancel);
cheevos_free_condition(&lb->submit); cheevos_free_condition(&lb->submit);
if ((void*)lb->value.terms)
free((void*)lb->value.terms); free((void*)lb->value.terms);
return -1; return -1;
} }
@ -1130,9 +1137,13 @@ static int cheevos_new_cheevo(cheevos_readud_t *ud)
return 0; return 0;
error: error:
if ((void*)cheevo->title)
free((void*)cheevo->title); free((void*)cheevo->title);
if ((void*)cheevo->description)
free((void*)cheevo->description); free((void*)cheevo->description);
if ((void*)cheevo->author)
free((void*)cheevo->author); free((void*)cheevo->author);
if ((void*)cheevo->badge)
free((void*)cheevo->badge); free((void*)cheevo->badge);
return -1; return -1;
} }
@ -1228,7 +1239,9 @@ static int cheevos_new_lboard(cheevos_readud_t *ud)
return 0; return 0;
error: error:
if ((void*)lboard->title)
free((void*)lboard->title); free((void*)lboard->title);
if ((void*)lboard->description)
free((void*)lboard->description); free((void*)lboard->description);
return -1; return -1;
} }
@ -1405,8 +1418,11 @@ static int cheevos_parse(const char *json)
if ( !cheevos_locals.core.cheevos || !cheevos_locals.unofficial.cheevos if ( !cheevos_locals.core.cheevos || !cheevos_locals.unofficial.cheevos
|| !cheevos_locals.leaderboards) || !cheevos_locals.leaderboards)
{ {
if ((void*)cheevos_locals.core.cheevos)
free((void*)cheevos_locals.core.cheevos); free((void*)cheevos_locals.core.cheevos);
if ((void*)cheevos_locals.unofficial.cheevos)
free((void*)cheevos_locals.unofficial.cheevos); free((void*)cheevos_locals.unofficial.cheevos);
if ((void*)cheevos_locals.leaderboards)
free((void*)cheevos_locals.leaderboards); free((void*)cheevos_locals.leaderboards);
cheevos_locals.core.count = cheevos_locals.unofficial.count = cheevos_locals.core.count = cheevos_locals.unofficial.count =
cheevos_locals.lboard_count = 0; cheevos_locals.lboard_count = 0;
@ -1964,14 +1980,19 @@ Free the loaded achievements.
static void cheevos_free_condset(const cheevos_condset_t *set) static void cheevos_free_condset(const cheevos_condset_t *set)
{ {
if ((void*)set->conds)
free((void*)set->conds); free((void*)set->conds);
} }
static void cheevos_free_cheevo(const cheevo_t *cheevo) static void cheevos_free_cheevo(const cheevo_t *cheevo)
{ {
if ((void*)cheevo->title)
free((void*)cheevo->title); free((void*)cheevo->title);
if ((void*)cheevo->description)
free((void*)cheevo->description); free((void*)cheevo->description);
if ((void*)cheevo->author)
free((void*)cheevo->author); free((void*)cheevo->author);
if ((void*)cheevo->badge)
free((void*)cheevo->badge); free((void*)cheevo->badge);
cheevos_free_condset(cheevo->condition.condsets); cheevos_free_condset(cheevo->condition.condsets);
} }
@ -1984,6 +2005,7 @@ static void cheevos_free_cheevo_set(const cheevoset_t *set)
while (cheevo < end) while (cheevo < end)
cheevos_free_cheevo(cheevo++); cheevos_free_cheevo(cheevo++);
if ((void*)set->cheevos)
free((void*)set->cheevos); free((void*)set->cheevos);
} }
@ -2757,10 +2779,12 @@ static int cheevos_iterate(coro_t* coro)
#endif #endif
if (cheevos_parse(CHEEVOS_VAR_JSON)) if (cheevos_parse(CHEEVOS_VAR_JSON))
{ {
if ((void*)CHEEVOS_VAR_JSON)
free((void*)CHEEVOS_VAR_JSON); free((void*)CHEEVOS_VAR_JSON);
CORO_STOP(); CORO_STOP();
} }
if ((void*)CHEEVOS_VAR_JSON)
free((void*)CHEEVOS_VAR_JSON); free((void*)CHEEVOS_VAR_JSON);
cheevos_loaded = true; cheevos_loaded = true;
@ -3052,11 +3076,13 @@ static int cheevos_iterate(coro_t* coro)
if (cheevos_get_value(CHEEVOS_VAR_JSON, CHEEVOS_JSON_KEY_GAMEID, gameid, sizeof(gameid))) if (cheevos_get_value(CHEEVOS_VAR_JSON, CHEEVOS_JSON_KEY_GAMEID, gameid, sizeof(gameid)))
{ {
if ((void*)CHEEVOS_VAR_JSON)
free((void*)CHEEVOS_VAR_JSON); free((void*)CHEEVOS_VAR_JSON);
RARCH_ERR("[CHEEVOS]: error getting game_id.\n"); RARCH_ERR("[CHEEVOS]: error getting game_id.\n");
CORO_RET(); CORO_RET();
} }
if ((void*)CHEEVOS_VAR_JSON)
free((void*)CHEEVOS_VAR_JSON); free((void*)CHEEVOS_VAR_JSON);
RARCH_LOG("[CHEEVOS]: got game id %s.\n", gameid); RARCH_LOG("[CHEEVOS]: got game id %s.\n", gameid);
CHEEVOS_VAR_GAMEID = strtol(gameid, NULL, 10); CHEEVOS_VAR_GAMEID = strtol(gameid, NULL, 10);
@ -3139,6 +3165,7 @@ static int cheevos_iterate(coro_t* coro)
if (CHEEVOS_VAR_JSON) if (CHEEVOS_VAR_JSON)
{ {
int res = cheevos_get_value(CHEEVOS_VAR_JSON, CHEEVOS_JSON_KEY_TOKEN, cheevos_locals.token, sizeof(cheevos_locals.token)); int res = cheevos_get_value(CHEEVOS_VAR_JSON, CHEEVOS_JSON_KEY_TOKEN, cheevos_locals.token, sizeof(cheevos_locals.token));
if ((void*)CHEEVOS_VAR_JSON)
free((void*)CHEEVOS_VAR_JSON); free((void*)CHEEVOS_VAR_JSON);
if (!res) if (!res)
@ -3282,6 +3309,7 @@ static int cheevos_iterate(coro_t* coro)
else else
RARCH_ERR("[CHEEVOS]: error deactivating unlocked achievements in softcore mode.\n"); RARCH_ERR("[CHEEVOS]: error deactivating unlocked achievements in softcore mode.\n");
if ((void*)CHEEVOS_VAR_JSON)
free((void*)CHEEVOS_VAR_JSON); free((void*)CHEEVOS_VAR_JSON);
} }
else else
@ -3310,6 +3338,7 @@ static int cheevos_iterate(coro_t* coro)
else else
RARCH_ERR("[CHEEVOS]: error deactivating unlocked achievements in hardcore mode.\n"); RARCH_ERR("[CHEEVOS]: error deactivating unlocked achievements in hardcore mode.\n");
if ((void*)CHEEVOS_VAR_JSON)
free((void*)CHEEVOS_VAR_JSON); free((void*)CHEEVOS_VAR_JSON);
} }
else else
@ -3343,6 +3372,7 @@ static int cheevos_iterate(coro_t* coro)
if (CHEEVOS_VAR_JSON) if (CHEEVOS_VAR_JSON)
{ {
RARCH_LOG("[CHEEVOS]: posted playing activity.\n"); RARCH_LOG("[CHEEVOS]: posted playing activity.\n");
if ((void*)CHEEVOS_VAR_JSON)
free((void*)CHEEVOS_VAR_JSON); free((void*)CHEEVOS_VAR_JSON);
} }
else else
@ -3361,8 +3391,11 @@ static void cheevos_task_handler(retro_task_t *task)
if (!cheevos_iterate(coro)) if (!cheevos_iterate(coro))
{ {
task_set_finished(task, true); task_set_finished(task, true);
if (CHEEVOS_VAR_DATA)
free(CHEEVOS_VAR_DATA); free(CHEEVOS_VAR_DATA);
if ((void*)CHEEVOS_VAR_PATH)
free((void*)CHEEVOS_VAR_PATH); free((void*)CHEEVOS_VAR_PATH);
if ((void*)coro)
free((void*)coro); free((void*)coro);
} }
} }
@ -3387,6 +3420,7 @@ bool cheevos_load(const void *data)
if (!task) if (!task)
{ {
if ((void*)coro)
free((void*)coro); free((void*)coro);
return false; return false;
} }
@ -3406,7 +3440,9 @@ bool cheevos_load(const void *data)
if (!CHEEVOS_VAR_DATA) if (!CHEEVOS_VAR_DATA)
{ {
if ((void*)task)
free((void*)task); free((void*)task);
if ((void*)coro)
free((void*)coro); free((void*)coro);
return false; return false;
} }