mirror of
https://github.com/troydhanson/tpl.git
synced 2024-12-26 23:57:25 +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
12
src/tpl.c
12
src/tpl.c
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user