[DGD]Using DGD_STRING_NEW correctly...
Michael J. Bacon
mj.bacon at gte.net
Fri Jun 22 20:10:30 CEST 2001
I think I am doing something "bad" with DGD_STRING_NEW because I'm creating
memory leaks like crazy. :-)
In an extension I have a loop that is creating a lot of strings and adding
them to a mapping. To do this I call DGD_STRING_NEW repeatedly. ie...
while (field != NULL)
str = DGD_STRING_NEW(field->name, strlen(field->name));
DGD_STRING_PUTVAL(nameval, str);
str2 = DGD_STRING_NEW(field->data, strlen(field->data));
DGD_STRING_PUTVAL(fieldval, str2);
DGD_MAPPING_ASSIGN(data, map, nameval, fieldval);
... lots of stuff edited out but this gives you the gist of what creates
the problem I think. When this function has finished there are a bunch of
leaked strings.
I tried using str_del() to free the string but under certain conditions it
would cause memory exceptions. When tracing through in the debugger,
assigning a string to a value with DGD_STRING_PUTVAL seems to increase the
reference counter as does assigning the values to the mapping.
What is the correct way to use dgd string pointers in extension loops?
Thanks;
Michael.
List config page: http://list.imaginary.com/mailman/listinfo/dgd
More information about the DGD
mailing list