Hello, On Sat, Jan 12, 2008 at 04:16:54PM +0200, Uoti Urpala wrote:
On Sat, 2008-01-12 at 15:05 +0100, reimar wrote:
+void stringset_free(stringset_t *set) { + free(*set); + *set = NULL; +} + +void stringset_add(stringset_t *set, const char *str) { + int count = 0; + while ((*set)[count]) count++; + count++; + *set = realloc(*set, sizeof(char *) * (count + 1)); + (*set)[count - 1] = strdup(str); + (*set)[count] = NULL; +}
Is there a need to strdup() the strings? The memory now allocated by strdup is not freed anywhere.
Honestly, no. Strictly there is not even a need for strings, as you pointed out at some other place, just e.g. the pointers to the codec structs would be enough. But (ignoring my ability to add a bug everywhere) the whole code is only 26 lines even when doing it in this general-purpose way and performance does not matter so I considered it preferable this way. If someone feels strongly about this, please feel free to change it any way you like (though consider adding proper doxygen comment so nobody uses it in a wrong way). Greetings, Reimar Döffinger