mirror of
https://github.com/troydhanson/tpl.git
synced 2024-12-25 23:31:00 +08:00
Fix memory leaks for the case described in #3
(strings in array of structures)
This commit is contained in:
parent
131a9b565f
commit
7adbfa38c9
22
src/tpl.c
22
src/tpl.c
@ -680,7 +680,7 @@ TPL_API void tpl_free(tpl_node *r) {
|
||||
int mmap_bits = (TPL_RDONLY|TPL_FILE);
|
||||
int ufree_bits = (TPL_MEM|TPL_UFREE);
|
||||
tpl_node *nxtc,*c;
|
||||
int find_next_node=0,looking,i;
|
||||
int find_next_node=0,looking,num,i;
|
||||
tpl_pidx *pidx,*pidx_nxt;
|
||||
|
||||
/* For mmap'd files, or for 'ufree' memory images , do appropriate release */
|
||||
@ -707,12 +707,20 @@ TPL_API void tpl_free(tpl_node *r) {
|
||||
break;
|
||||
case TPL_TYPE_STR:
|
||||
/* free any packed (copied) string */
|
||||
for(i=0; i < c->num; i++) {
|
||||
char *str = ((char**)c->data)[i];
|
||||
if (str) {
|
||||
tpl_hook.free(str);
|
||||
((char**)c->data)[i] = NULL;
|
||||
}
|
||||
num = 1;
|
||||
nxtc = c->next;
|
||||
while (nxtc) {
|
||||
if (nxtc->type == TPL_TYPE_POUND) {
|
||||
num = nxtc->num;
|
||||
}
|
||||
nxtc = nxtc->next;
|
||||
}
|
||||
for (i = 0; i < c->num * num; i++) {
|
||||
char *str = ((char**)c->data)[i];
|
||||
if (str) {
|
||||
tpl_hook.free(str);
|
||||
((char**)c->data)[i] = NULL;
|
||||
}
|
||||
}
|
||||
tpl_hook.free(c->data);
|
||||
find_next_node=1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user