summaryrefslogtreecommitdiff
path: root/lib/sendf.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-08-22 19:38:17 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-08-22 19:38:17 +0000
commit394832c2d6fc47b10858491193b54e8f573f1fb9 (patch)
tree5488a5476fa83378e5fdf7e96ca6e8e7ab639784 /lib/sendf.c
parentf636c12255869039ff7874ce3b02363f327e427e (diff)
downloadcurl-394832c2d6fc47b10858491193b54e8f573f1fb9.tar.gz
Markus Oberhumer improved an out-of-memory check
I reformatted some functions using a different indent than the rest of the file.
Diffstat (limited to 'lib/sendf.c')
-rw-r--r--lib/sendf.c93
1 files changed, 46 insertions, 47 deletions
diff --git a/lib/sendf.c b/lib/sendf.c
index e20b147bf..886bd8e79 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;
-
- /* 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, ...)