void
wordlistDestroy(wordlist ** list)
{
- wordlist *w = NULL;
-
- while ((w = *list) != NULL) {
- *list = w->next;
- safe_free(w->key);
- delete w;
+ while (*list != nullptr) {
+ const char *k = wordlistChopHead(list);
+ safe_free(k);
}
-
- *list = NULL;
}
const char *
class wordlist
{
MEMPROXY_CLASS(wordlist);
- friend void wordlistDestroy(wordlist ** list);
friend char *wordlistChopHead(wordlist **);
public:
wordlist *next;
private:
- // use wordlistDestroy instead
+ // does not free data members.
~wordlist() = default;
};
/// destroy a wordlist
void wordlistDestroy(wordlist **);
-/** remove the first element in a wordlist, and return its key
+/** Remove and destroy the first element while preserving and returning its key
*
* \note the returned key must be freed by the caller using safe_free
* \note wl is altered so that it points to the second element