From: Francesco Chemolli Date: Fri, 25 Sep 2015 12:27:33 +0000 (+0200) Subject: Rework wordlistDestroy and refine documentation for wordlist as suggested by Alex X-Git-Tag: SQUID_4_0_1~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f373c58ff4ec4f3684c153c62296267e56b7617;p=thirdparty%2Fsquid.git Rework wordlistDestroy and refine documentation for wordlist as suggested by Alex --- diff --git a/src/wordlist.cc b/src/wordlist.cc index ef342f7346..f508bb5a09 100644 --- a/src/wordlist.cc +++ b/src/wordlist.cc @@ -15,15 +15,10 @@ 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 * diff --git a/src/wordlist.h b/src/wordlist.h index 2dc2971b9c..85639a10f6 100644 --- a/src/wordlist.h +++ b/src/wordlist.h @@ -20,7 +20,6 @@ class wordlist { MEMPROXY_CLASS(wordlist); - friend void wordlistDestroy(wordlist ** list); friend char *wordlistChopHead(wordlist **); public: @@ -35,7 +34,7 @@ public: wordlist *next; private: - // use wordlistDestroy instead + // does not free data members. ~wordlist() = default; }; @@ -68,7 +67,7 @@ void wordlistJoin(wordlist **, wordlist **); /// 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