From 394832c2d6fc47b10858491193b54e8f573f1fb9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 22 Aug 2002 19:38:17 +0000 Subject: [PATCH] Markus Oberhumer improved an out-of-memory check I reformatted some functions using a different indent than the rest of the file. --- lib/sendf.c | 83 ++++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/lib/sendf.c b/lib/sendf.c index e20b147bfe..886bd8e79f 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -62,18 +62,18 @@ /* returns last node in linked list */ static struct curl_slist *slist_get_last(struct curl_slist *list) { - struct curl_slist *item; + struct curl_slist *item; - /* if caller passed us a NULL, return now */ - if (!list) - return NULL; + /* 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; + /* 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; + 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; - } + 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 (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; + /* 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, ...)