]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Rework wordlistDestroy and refine documentation for wordlist as suggested by Alex
authorFrancesco Chemolli <kinkie@squid-cache.org>
Fri, 25 Sep 2015 12:27:33 +0000 (14:27 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Fri, 25 Sep 2015 12:27:33 +0000 (14:27 +0200)
src/wordlist.cc
src/wordlist.h

index ef342f7346c0ba1d7900f336aa7a97b1d431e5ce..f508bb5a09cd62f3a4f814b76eb9223411a251ad 100644 (file)
 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 *
index 2dc2971b9c859e739c3aa41bfd3fa9c2de38f61b..85639a10f61854d6b0794f39fd2a47e4a164ef13 100644 (file)
@@ -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