[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
ldap-c-api: malloced vs. "ldap alloced" data
I have several programs (written by both me and others) that trust
ldap_value_free(array) to be implemented as
free() each element in <array>;
free() <array> itself.
That is, they do things like
- rearrange (e.g. sort) and maybe free() some of the strings
in the array returned by ldap_get_values().
- build a fake ldap_get_values() return value.
The draft does not promise that this is OK. Do we want it to?
If not, some of my programs must copy most output of ldap_get_values()
to an equivalent private array which *is* double-malloced as above.
Easy enough, but wasteful.
Example of an implementation which breaks the assumptions above:
ldap_value_free(array):
free(array[0]); /* One malloced array with all the strings */
free(array); /* ...and poiners into that array */
ldap_explode_*dn() and ldap_get_values():
char **array = malloc(<big enough>), **ap = array;
char *text = malloc(<big enough for all the strings>), *tp = text;
for (char *val = <first>; val; val = <next>) {
*ap++ = strcpy(tp, val);
tp += strlen(val) + 1;
}
*ap = NULL;
return ap;
--
Hallvard