Log a message right before exiting gracefully
[privoxy.git] / list.c
diff --git a/list.c b/list.c
index fcafb57..b9963af 100644 (file)
--- a/list.c
+++ b/list.c
@@ -1,12 +1,11 @@
-const char list_rcs[] = "$Id: list.c,v 1.28 2012/03/09 16:23:50 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/list.c,v $
  *
  * Purpose     :  Declares functions to handle lists.
  *
- * Copyright   :  Written by and Copyright (C) 2001-2007 the SourceForge
- *                Privoxy team. http://www.privoxy.org/
+ * Copyright   :  Written by and Copyright (C) 2001-2007 members of the
+ *                Privoxy team. https://www.privoxy.org/
  *
  *                Based on the Internet Junkbuster originally written
  *                by and Copyright (C) 1997 Anonymous Coders and
@@ -46,7 +45,7 @@ const char list_rcs[] = "$Id: list.c,v 1.28 2012/03/09 16:23:50 fabiankeil Exp $
 #endif
 #include <string.h>
 
-#if !defined(_WIN32) && !defined(__OS2__)
+#if !defined(_WIN32)
 #include <unistd.h>
 #endif
 
@@ -56,9 +55,6 @@ const char list_rcs[] = "$Id: list.c,v 1.28 2012/03/09 16:23:50 fabiankeil Exp $
 #include "list.h"
 #include "miscutil.h"
 
-const char list_h_rcs[] = LIST_H_VERSION;
-
-
 static int list_is_valid (const struct list *the_list);
 
 
@@ -134,7 +130,7 @@ void destroy_list (struct list *the_list)
  * Description :  Check that a string list is valid.  The intended
  *                usage is "assert(list_is_valid(the_list))".
  *                Currently this checks that "the_list->last"
- *                is correct, and that the list dosn't contain
+ *                is correct, and that the list doesn't contain
  *                circular references.  It is likely to crash if
  *                it's passed complete garbage.
  *
@@ -876,15 +872,24 @@ int list_contains_item(const struct list *the_list, const char *str)
  * Function    :  new_map
  *
  * Description :  Create a new, empty map.
+ *                Causes program exit if the memory allocation fails.
  *
  * Parameters  :  N/A
  *
- * Returns     :  A new, empty map, or NULL if out of memory.
+ * Returns     :  A new, empty map
  *
  *********************************************************************/
 struct map *new_map(void)
 {
-   return (struct map *) zalloc(sizeof(struct map));
+   struct map *empty_map = zalloc(sizeof(struct map));
+
+   if (NULL == empty_map)
+   {
+      exit(1);
+   }
+
+   return empty_map;
+
 }
 
 
@@ -893,7 +898,7 @@ struct map *new_map(void)
  * Function    :  free_map
  *
  * Description :  Free the memory occupied by a map and its
- *                depandant strings
+ *                dependent strings
  *
  * Parameters  :
  *          1  :  the_map = map to be freed.  May be NULL.
@@ -1055,7 +1060,7 @@ jb_err unmap(struct map *the_map, const char *name)
    assert(the_map);
    assert(name);
 
-   last_entry = the_map->first;
+   last_entry = NULL;
 
    for (cur_entry = the_map->first; cur_entry != NULL; cur_entry = cur_entry->next)
    {
@@ -1087,7 +1092,11 @@ jb_err unmap(struct map *the_map, const char *name)
          freez(cur_entry->name);
          freez(cur_entry->value);
          freez(cur_entry);
-
+         if (last_entry == NULL)
+         {
+            /* The map only had a single entry which has just been removed. */
+            break;
+         }
          cur_entry = last_entry;
       }
       else
@@ -1111,7 +1120,7 @@ jb_err unmap(struct map *the_map, const char *name)
  *          2  :  name = name parameter to look for
  *
  * Returns     :  the value if found, else the empty string.
- *                Return value is alloced as part of the map, so
+ *                Return value is allocated as part of the map, so
  *                it is freed when the map is destroyed.  Caller
  *                must not free or modify it.
  *