mirror of https://github.com/moparisthebest/curl
curl_slist_append() fixed to clear up properly if a memory function fails
This commit is contained in:
parent
329f17ac7c
commit
b8541929c8
26
lib/sendf.c
26
lib/sendf.c
|
@ -74,11 +74,13 @@ static struct curl_slist *slist_get_last(struct curl_slist *list)
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* append a struct to the linked list. It always retunrs the address of the
|
/*
|
||||||
* first record, so that you can sure this function as an initialization
|
* curl_slist_append() appends a string to the linked list. It always retunrs
|
||||||
* function as well as an append function. If you find this bothersome,
|
* the address of the first record, so that you can sure this function as an
|
||||||
* then simply create a separate _init function and call it appropriately from
|
* initialization function as well as an append function. If you find this
|
||||||
* within the proram. */
|
* bothersome, then simply create a separate _init function and call it
|
||||||
|
* appropriately from within the proram.
|
||||||
|
*/
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
@ -87,12 +89,18 @@ struct curl_slist *curl_slist_append(struct curl_slist *list,
|
||||||
|
|
||||||
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;
|
char *dup = strdup(data);
|
||||||
new_item->data = strdup(data);
|
if(dup) {
|
||||||
|
new_item->next = NULL;
|
||||||
|
new_item->data = dup;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
free(new_item);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (new_item == NULL || new_item->data == NULL) {
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (list) {
|
if (list) {
|
||||||
last = slist_get_last(list);
|
last = slist_get_last(list);
|
||||||
|
|
Loading…
Reference in New Issue