Skip to content

Commit

Permalink
Fixed memory leaks from item random options
Browse files Browse the repository at this point in the history
  • Loading branch information
Lemongrass3110 committed Aug 15, 2016
1 parent 3d94626 commit e2bf685
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/map/itemdb.c
Expand Up @@ -1763,6 +1763,15 @@ static int itemdb_group_free(DBKey key, DBData *data, va_list ap) {
return 0;
}

static int itemdb_randomopt_free(DBKey key, DBData *data, va_list ap) {
struct s_random_opt_data *opt = (struct s_random_opt_data *)db_data2ptr(data);
if (!opt)
return 0;
if (opt->script)
script_free_code(opt->script);
return 1;
}

/**
* Reload Item DB
*/
Expand All @@ -1773,6 +1782,7 @@ void itemdb_reload(void) {
int i,d,k;

itemdb_group->clear(itemdb_group, itemdb_group_free);
itemdb_randomopt->clear(itemdb_randomopt, itemdb_randomopt_free);
itemdb->clear(itemdb, itemdb_final_sub);
db_clear(itemdb_combo);
if (battle_config.feature_roulette)
Expand Down Expand Up @@ -1840,6 +1850,7 @@ void itemdb_reload(void) {
void do_final_itemdb(void) {
db_destroy(itemdb_combo);
itemdb_group->destroy(itemdb_group, itemdb_group_free);
itemdb_randomopt->destroy(itemdb_randomopt, itemdb_randomopt_free);
itemdb->destroy(itemdb, itemdb_final_sub);
destroy_item_data(dummy_item);
if (battle_config.feature_roulette)
Expand Down

0 comments on commit e2bf685

Please sign in to comment.