Let new_map() exit if the new map can't be allocated
authorFabian Keil <fk@fabiankeil.de>
Sat, 18 Oct 2014 11:31:52 +0000 (11:31 +0000)
committerFabian Keil <fk@fabiankeil.de>
Sat, 18 Oct 2014 11:31:52 +0000 (11:31 +0000)
This is not expected to happen in the real world
and it makes life easier for the callers.

cgi.c
cgiedit.c
list.c

diff --git a/cgi.c b/cgi.c
index 4f7710d..1307b87 100644 (file)
--- a/cgi.c
+++ b/cgi.c
@@ -1,4 +1,4 @@
-const char cgi_rcs[] = "$Id: cgi.c,v 1.158 2012/12/07 12:45:20 fabiankeil Exp $";
+const char cgi_rcs[] = "$Id: cgi.c,v 1.159 2014/10/18 11:31:25 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/cgi.c,v $
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/cgi.c,v $
@@ -495,14 +495,12 @@ static struct http_response *dispatch_known_cgi(struct client_state * csp,
    if (*query_args_start == '/')
    {
       *query_args_start++ = '\0';
    if (*query_args_start == '/')
    {
       *query_args_start++ = '\0';
-      if ((param_list = new_map()))
-      {
-         err = map(param_list, "file", 1, url_decode(query_args_start), 0);
-         if (JB_ERR_OK != err) {
-            free(path_copy);
-            free(param_list);
-            return cgi_error_memory();
-         }
+      param_list = new_map();
+      err = map(param_list, "file", 1, url_decode(query_args_start), 0);
+      if (JB_ERR_OK != err) {
+         free(param_list);
+         free(path_copy);
+         return cgi_error_memory();
       }
    }
    else
       }
    }
    else
@@ -636,11 +634,7 @@ static struct map *parse_cgi_parameters(char *argstring)
    }
    vector = malloc_or_die(max_segments * sizeof(char *));
 
    }
    vector = malloc_or_die(max_segments * sizeof(char *));
 
-   if (NULL == (cgi_params = new_map()))
-   {
-      freez(vector);
-      return NULL;
-   }
+   cgi_params = new_map();
 
    /*
     * IE 5 does, of course, violate RFC 2316 Sect 4.1 and sends
 
    /*
     * IE 5 does, of course, violate RFC 2316 Sect 4.1 and sends
@@ -2167,10 +2161,6 @@ struct map *default_exports(const struct client_state *csp, const char *caller)
    assert(csp);
 
    exports = new_map();
    assert(csp);
 
    exports = new_map();
-   if (exports == NULL)
-   {
-      return NULL;
-   }
 
    if (csp->config->hostname)
    {
 
    if (csp->config->hostname)
    {
index ca74ccc..8463328 100644 (file)
--- a/cgiedit.c
+++ b/cgiedit.c
@@ -1,4 +1,4 @@
-const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.85 2014/10/18 11:29:22 fabiankeil Exp $";
+const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.86 2014/10/18 11:29:48 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/cgiedit.c,v $
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/cgiedit.c,v $
@@ -2342,7 +2342,7 @@ jb_err cgi_edit_actions_list(struct client_state *csp,
             {
                if (!strncmp(b->url->spec, "standard.", 9) && *(b->url->spec + 9) != '\0')
                {
             {
                if (!strncmp(b->url->spec, "standard.", 9) && *(b->url->spec + 9) != '\0')
                {
-                  if (err || (NULL == (section_exports = new_map())))
+                  if (err)
                   {
                      freez(buttons);
                      free(section_template);
                   {
                      freez(buttons);
                      free(section_template);
@@ -2351,6 +2351,7 @@ jb_err cgi_edit_actions_list(struct client_state *csp,
                      return JB_ERR_MEMORY;
                   }
 
                      return JB_ERR_MEMORY;
                   }
 
+                  section_exports = new_map();
                   err = map(section_exports, "button-name", 1, b->url->spec + 9, 1);
 
                   if (err || (NULL == (s = strdup(section_template))))
                   err = map(section_exports, "button-name", 1, b->url->spec + 9, 1);
 
                   if (err || (NULL == (s = strdup(section_template))))
@@ -2482,15 +2483,7 @@ jb_err cgi_edit_actions_list(struct client_state *csp,
 
    while ((cur_line != NULL) && (cur_line->type == FILE_LINE_ACTION))
    {
 
    while ((cur_line != NULL) && (cur_line->type == FILE_LINE_ACTION))
    {
-      if (NULL == (section_exports = new_map()))
-      {
-         free(sections);
-         free(section_template);
-         free(url_template);
-         edit_free_file(file);
-         free_map(exports);
-         return JB_ERR_MEMORY;
-      }
+      section_exports = new_map();
 
       snprintf(buf, sizeof(buf), "%u", line_number);
       err = map(section_exports, "s", 1, buf, 1);
 
       snprintf(buf, sizeof(buf), "%u", line_number);
       err = map(section_exports, "s", 1, buf, 1);
@@ -2554,17 +2547,7 @@ jb_err cgi_edit_actions_list(struct client_state *csp,
 
       while ((cur_line != NULL) && (cur_line->type == FILE_LINE_URL))
       {
 
       while ((cur_line != NULL) && (cur_line->type == FILE_LINE_URL))
       {
-         if (NULL == (url_exports = new_map()))
-         {
-            free(urls);
-            free(sections);
-            free(section_template);
-            free(url_template);
-            edit_free_file(file);
-            free_map(exports);
-            free_map(section_exports);
-            return JB_ERR_MEMORY;
-         }
+         url_exports = new_map();
 
          snprintf(buf, sizeof(buf), "%u", line_number);
          err = map(url_exports, "p", 1, buf, 1);
 
          snprintf(buf, sizeof(buf), "%u", line_number);
          err = map(url_exports, "p", 1, buf, 1);
diff --git a/list.c b/list.c
index fcafb57..d987814 100644 (file)
--- a/list.c
+++ b/list.c
@@ -1,4 +1,4 @@
-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.29 2012/03/09 17:55:50 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/list.c,v $
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/list.c,v $
@@ -876,15 +876,24 @@ int list_contains_item(const struct list *the_list, const char *str)
  * Function    :  new_map
  *
  * Description :  Create a new, empty map.
  * Function    :  new_map
  *
  * Description :  Create a new, empty map.
+ *                Causes program exit if the memory allocation fails.
  *
  * Parameters  :  N/A
  *
  *
  * Parameters  :  N/A
  *
- * Returns     :  A new, empty map, or NULL if out of memory.
+ * Returns     :  A new, empty map
  *
  *********************************************************************/
 struct map *new_map(void)
 {
  *
  *********************************************************************/
 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;
+
 }
 
 
 }