summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2019-12-15 12:33:24 +0100
committerDaniel Stenberg <daniel@haxx.se>2019-12-15 18:19:01 +0100
commit38797e8811a9249d0ce988d664c89802b6235f2d (patch)
treefdd922cfea3cbca7813fd8f60e364ef4d427577a /tests
parent571f2c81d10e9093b4eb91b3714f640af4c9eab1 (diff)
downloadcurl-38797e8811a9249d0ce988d664c89802b6235f2d.tar.gz
lib1591: free memory properly on OOM, in the trailers callback
Detected by torture tests. Closes #4720
Diffstat (limited to 'tests')
-rw-r--r--tests/libtest/lib1591.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/tests/libtest/lib1591.c b/tests/libtest/lib1591.c
index f0c6b4cb7..cc1c5b228 100644
--- a/tests/libtest/lib1591.c
+++ b/tests/libtest/lib1591.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -50,12 +50,25 @@ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
return amount;
}
+/*
+ * carefully not leak memory on OOM
+ */
static int trailers_callback(struct curl_slist **list, void *userdata)
{
+ struct curl_slist *nlist = NULL;
+ struct curl_slist *nlist2 = NULL;
(void)userdata;
- *list = curl_slist_append(*list, "my-super-awesome-trailer: trail1");
- *list = curl_slist_append(*list, "my-other-awesome-trailer: trail2");
- return CURL_TRAILERFUNC_OK;
+ nlist = curl_slist_append(*list, "my-super-awesome-trailer: trail1");
+ if(nlist)
+ nlist2 = curl_slist_append(nlist, "my-other-awesome-trailer: trail2");
+ if(nlist2) {
+ *list = nlist2;
+ return CURL_TRAILERFUNC_OK;
+ }
+ else {
+ curl_slist_free_all(nlist);
+ return CURL_TRAILERFUNC_ABORT;
+ }
}
int test(char *URL)