If I do this:
PIKEFUN array(array(string)) test() { struct array *a; int i; a = allocate_array_no_init(0, 10); for (; a->size < 10; a->size++) { ITEM(a)[a->size].type = T_ARRAY; ITEM(a)[a->size].u.array = allocate_array_no_init(2, 0); for (i = 0; i < 2; i++) { ITEM(ITEM(a)[a->size].u.array)[i].type = T_STRING; ITEM(ITEM(a)[a->size].u.array)[i].u.string = make_shared_string("foo"); } } RETURN (a); }
Then it leaks memory. But if I add in an extra counter and do it like so:
PIKEFUN array(array(string)) test() { struct array *a; int i, j; a = allocate_array_no_init(10, 0); for (j = 0; j < 10; j++) { ITEM(a)[j].type = T_ARRAY; ITEM(a)[j].u.array = allocate_array_no_init(2, 0); for (i = 0; i < 2; i++) { ITEM(ITEM(a)[j].u.array)[i].type = T_STRING; ITEM(ITEM(a)[j].u.array)[i].u.string = make_shared_string("foo"); } } RETURN (a); }
Then everything is fine. It doesn't look like really_free_array() cares about malloced_size, just size?
Adam