From daabda7c8b4038ac24cdf5b9790932905eab7d8f Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 17 Feb 2009 03:14:49 +0100 Subject: Improving stalloc by make it context-safe. --- mpq-fs.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'mpq-fs.c') diff --git a/mpq-fs.c b/mpq-fs.c index 160fdcd..c055b17 100644 --- a/mpq-fs.c +++ b/mpq-fs.c @@ -28,6 +28,7 @@ static char * strnormalize(char * _str) { } htab * hash_table = 0; +struct st_alloc_t * st = 0; static void add_file(struct mpq_archive_t * mpq_a, char * fname) { int entry; @@ -36,13 +37,15 @@ static void add_file(struct mpq_archive_t * mpq_a, char * fname) { if ((entry = mpqlib_find_hash_entry_by_name(mpq_a, fname, 0, 0)) < 0) return; - if (!hash_table) + if (!hash_table) { hash_table = hcreate(INITIAL_HASH_SIZE); + st = st_init(); + } - nfname = strnormalize(st_strdup(fname)); + nfname = strnormalize(st_strdup(st, fname)); hadd(hash_table, (uint8_t *) nfname, strlen(nfname), NULL); if (!hstuff(hash_table)) { - hstuff(hash_table) = st_alloc(sizeof(hash_entry)); + hstuff(hash_table) = st_alloc(st, sizeof(hash_entry)); } ((hash_entry *) hstuff(hash_table))->mpq_a = mpq_a; ((hash_entry *) hstuff(hash_table))->entry = entry; @@ -155,14 +158,8 @@ int mpqlib_fs_filelist(char * buffer) { void mpqlib_fs_shutdown() { if (!hash_table) return; -/* - if (hfirst(hash_table)) do { - free(hstuff(hash_table)); - free(hkey(hash_table)); - } while (hnext(hash_table)); -*/ - st_shutdown(); + st_destroy(st); hdestroy(hash_table); hash_table = 0; } -- cgit v1.2.3