Markus Oberhumer improved an out-of-memory check
authorDaniel Stenberg <daniel@haxx.se>
Thu, 22 Aug 2002 19:38:17 +0000 (19:38 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 22 Aug 2002 19:38:17 +0000 (19:38 +0000)
I reformatted some functions using a different indent than the rest
of the file.

lib/sendf.c

index e20b147bfe843689ec20826e1441b46cdceed1fd..886bd8e79fcfc72a48cd74b31354f54015da4b85 100644 (file)
 /* returns last node in linked list */
 static struct curl_slist *slist_get_last(struct curl_slist *list)
 {
-       struct curl_slist       *item;
-
-       /* if caller passed us a NULL, return now */
-       if (!list)
-               return NULL;
-
-       /* loop through to find the last item */
-       item = list;
-       while (item->next) {
-               item = item->next;
-       }
-       return item;
+  struct curl_slist    *item;
+
+  /* if caller passed us a NULL, return now */
+  if (!list)
+    return NULL;
+
+  /* loop through to find the last item */
+  item = list;
+  while (item->next) {
+    item = item->next;
+  }
+  return item;
 }
 
 /* append a struct to the linked list. It always retunrs the address of the
@@ -84,51 +84,50 @@ static struct curl_slist *slist_get_last(struct curl_slist *list)
 struct curl_slist *curl_slist_append(struct curl_slist *list,
                                      const char *data)
 {
-       struct curl_slist       *last;
-       struct curl_slist       *new_item;
-
-       new_item = (struct curl_slist *) malloc(sizeof(struct curl_slist));
-       if (new_item) {
-               new_item->next = NULL;
-               new_item->data = strdup(data);
-       }
-       else {
-               fprintf(stderr, "Cannot allocate memory for QUOTE list.\n");
-               return NULL;
-       }
-
-       if (list) {
-               last = slist_get_last(list);
-               last->next = new_item;
-               return list;
-       }
-
-       /* if this is the first item, then new_item *is* the list */
-       return new_item;
+  struct curl_slist    *last;
+  struct curl_slist    *new_item;
+
+  new_item = (struct curl_slist *) malloc(sizeof(struct curl_slist));
+  if (new_item) {
+    new_item->next = NULL;
+    new_item->data = strdup(data);
+  }
+  if (new_item == NULL || new_item->data == NULL) {
+    fprintf(stderr, "Cannot allocate memory for QUOTE list.\n");
+    return NULL;
+  }
+
+  if (list) {
+    last = slist_get_last(list);
+    last->next = new_item;
+    return list;
+  }
+
+  /* if this is the first item, then new_item *is* the list */
+  return new_item;
 }
 
 /* be nice and clean up resources */
 void curl_slist_free_all(struct curl_slist *list)
 {
-       struct curl_slist       *next;
-       struct curl_slist       *item;
+  struct curl_slist    *next;
+  struct curl_slist    *item;
 
-       if (!list)
-               return;
+  if (!list)
+    return;
 
-       item = list;
-       do {
-               next = item->next;
+  item = list;
+  do {
+    next = item->next;
                
-               if (item->data) {
-                       free(item->data);
-               }
-               free(item);
-               item = next;
-       } while (next);
+    if (item->data) {
+      free(item->data);
+    }
+    free(item);
+    item = next;
+  } while (next);
 }
 
-
 /* Curl_infof() is for info message along the way */
 
 void Curl_infof(struct SessionHandle *data, const char *fmt, ...)