diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-03-01 20:02:02 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-03-01 20:02:02 +0300 |
commit | 778ebbc853430bbe0720612a4980cbe371d8186f (patch) | |
tree | 5520040de343b530308358c8c34c509774dc35f5 /src | |
parent | 594452c2495b2bc3e376a4b927f5992f9fc8b5db (diff) | |
download | evol-hercules-778ebbc853430bbe0720612a4980cbe371d8186f.tar.gz evol-hercules-778ebbc853430bbe0720612a4980cbe371d8186f.tar.bz2 evol-hercules-778ebbc853430bbe0720612a4980cbe371d8186f.tar.xz evol-hercules-778ebbc853430bbe0720612a4980cbe371d8186f.zip |
Fix memory leak in lang.c on exit.
Diffstat (limited to 'src')
-rw-r--r-- | src/map/lang.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/map/lang.c b/src/map/lang.c index 6264cef..45be125 100644 --- a/src/map/lang.c +++ b/src/map/lang.c @@ -34,9 +34,26 @@ void do_init_langs (void) langsdb_readdb (); } +static int delete_lang_sub(DBKey key __attribute__ ((unused)), + DBData *data, + va_list args __attribute__ ((unused))) +{ + int f; + char **strings = DB->data2ptr(data); + for (f = 0; f < lang_num; f ++) + { + aFree(strings[f]); + strings[f] = NULL; + } + return 0; +} + void do_final_langs(void) { - db_destroy(translate_db); + translate_db->destroy(translate_db, delete_lang_sub); + int f; + for (f = 0; f < lang_num; f ++) + aFree(lang_langs[f]); } static int langsdb_readlangs (void) @@ -123,10 +140,12 @@ static int langsdb_readdb (void) strcpy (strings[0], line1); strdb_put(translate_db, aStrdup (line1), strings); } - - sz = strlen(line2) + 1; - strings[i] = aCalloc (sz < 24 ? 24 : sz, sizeof(char)); - strcpy (strings[i], line2); + else + { + sz = strlen(line2) + 1; + strings[i] = aCalloc (sz < 24 ? 24 : sz, sizeof(char)); + strcpy (strings[i], line2); + } *line1 = 0; *line2 = 0; |