-const char list_rcs[] = "$Id: list.c,v 1.28 2012/03/09 16:23:50 fabiankeil Exp $";
+const char list_rcs[] = "$Id: list.c,v 1.31 2014/10/21 12:01:59 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/list.c,v $
* 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;
+
}
* 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.
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)
{
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