Fix memory leaks for the case described in #3

(strings in array of structures)
This commit is contained in:
Andrei Diaconu 2013-07-11 11:03:15 +02:00 committed by tbeu
parent 131a9b565f
commit 7adbfa38c9

View File

@ -680,7 +680,7 @@ TPL_API void tpl_free(tpl_node *r) {
int mmap_bits = (TPL_RDONLY|TPL_FILE); int mmap_bits = (TPL_RDONLY|TPL_FILE);
int ufree_bits = (TPL_MEM|TPL_UFREE); int ufree_bits = (TPL_MEM|TPL_UFREE);
tpl_node *nxtc,*c; tpl_node *nxtc,*c;
int find_next_node=0,looking,i; int find_next_node=0,looking,num,i;
tpl_pidx *pidx,*pidx_nxt; tpl_pidx *pidx,*pidx_nxt;
/* For mmap'd files, or for 'ufree' memory images , do appropriate release */ /* For mmap'd files, or for 'ufree' memory images , do appropriate release */
@ -707,7 +707,15 @@ TPL_API void tpl_free(tpl_node *r) {
break; break;
case TPL_TYPE_STR: case TPL_TYPE_STR:
/* free any packed (copied) string */ /* free any packed (copied) string */
for(i=0; i < c->num; i++) { 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]; char *str = ((char**)c->data)[i];
if (str) { if (str) {
tpl_hook.free(str); tpl_hook.free(str);