1
0
mirror of https://github.com/moparisthebest/curl synced 2025-03-11 07:39:50 -04:00

Markus Oberhumer improved an out-of-memory check

I reformatted some functions using a different indent than the rest
of the file.
This commit is contained in:
Daniel Stenberg 2002-08-22 19:38:17 +00:00
parent f636c12255
commit 394832c2d6

View File

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