[DGD]Using DGD_STRING_NEW correctly...
Michael J. Bacon
mj.bacon at gte.net
Fri Jun 22 23:31:46 CEST 2001
> Show us the money^Wcode!
> Erwin.
Okie dokie here is the entire while statement...
----
while (field != NULL) {
str = DGD_STRING_NEW(field->name, strlen(field->name));
DGD_STRING_PUTVAL(nameval, str);
switch (field->type) {
case FT_FLOAT:
memcpy(&floatval, (double *)field->data, sizeof(double));
sign = (floatval < 0);
mantissa = ldexp(frexp(fabs(floatval), &exp), 37);
--exp;
DGD_FLOAT_PUT(flt, sign, exp, mantissa);
DGD_FLOAT_PUTVAL(fieldval, flt);
DGD_MAPPING_ASSIGN(data, map, nameval, fieldval);
break;
case FT_STRING:
case FT_HPM:
str = DGD_STRING_NEW((char *)field->data, strlen((char *)field->data));
DGD_STRING_PUTVAL(fieldval, str);
DGD_MAPPING_ASSIGN(data, map, nameval, fieldval);
break;
case FT_LONG:
memcpy(&intval, (long *)field->data, sizeof(long));
DGD_INT_PUTVAL(fieldval, intval);
DGD_MAPPING_ASSIGN(data, map, nameval, fieldval);
break;
case FT_DATE:
str = DGD_STRING_NEW((char *)field->data, strlen((char *)field->data));
DGD_STRING_PUTVAL(fieldval, str);
DGD_MAPPING_ASSIGN(data, map, nameval, fieldval);
break;
}
free(field->name);
if (field->data != NULL)
free(field->data);
if (field->next != NULL) {
field = field->next;
free(field->prev);
} else {
free(field);
field = NULL;
}
}
DGD_RETVAL_MAP(retval, map);
----
It leaks the field name string when the switch statement falls into the
STRING, HPM or DATE cases. Over time I can rack up several hundred leaked
strings.
Thanks;
Michael.
List config page: http://list.imaginary.com/mailman/listinfo/dgd
More information about the DGD
mailing list