diff --git a/tests/libtest/lib1526.c b/tests/libtest/lib1526.c
index fb757f5928d21b4cd5f937f0930911a66b9260e0..ec21fb00a830f0c0b9f76b4801d30f7fda5d3097 100644
--- a/tests/libtest/lib1526.c
+++ b/tests/libtest/lib1526.c
@@ -47,7 +47,7 @@ int test(char *URL)
   CURL *curl = NULL;
   CURLcode res = CURLE_FAILED_INIT;
   /* http and proxy header list*/
-  struct curl_slist *hhl = NULL, *phl = NULL;
+  struct curl_slist *hhl = NULL, *phl = NULL, *tmp = NULL;
 
   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
     fprintf(stderr, "curl_global_init() failed\n");
@@ -62,11 +62,14 @@ int test(char *URL)
 
   hhl = curl_slist_append(hhl, "User-Agent: Http Agent");
   phl = curl_slist_append(phl, "User-Agent: Proxy Agent");
-  phl = curl_slist_append(phl, "Expect:");
-
   if (!hhl || !phl) {
     goto test_cleanup;
   }
+  tmp = curl_slist_append(phl, "Expect:");
+  if (!tmp) {
+    goto test_cleanup;
+  }
+  phl = tmp;
 
   test_setopt(curl, CURLOPT_URL, URL);
   test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
diff --git a/tests/libtest/lib1527.c b/tests/libtest/lib1527.c
index 41792f14ad896f8492ceefacc0b3ef264387665b..280c947e33b20dc2109a444c3928af7fd33ecbd2 100644
--- a/tests/libtest/lib1527.c
+++ b/tests/libtest/lib1527.c
@@ -48,7 +48,7 @@ int test(char *URL)
   CURL *curl = NULL;
   CURLcode res = CURLE_FAILED_INIT;
   /* http header list*/
-  struct curl_slist *hhl = NULL;
+  struct curl_slist *hhl = NULL, *tmp = NULL;
 
   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
     fprintf(stderr, "curl_global_init() failed\n");
@@ -62,11 +62,14 @@ int test(char *URL)
   }
 
   hhl = curl_slist_append(hhl, "User-Agent: Http Agent");
-  hhl = curl_slist_append(hhl, "Expect: 100-continue");
-
   if (!hhl) {
     goto test_cleanup;
   }
+  tmp = curl_slist_append(hhl, "Expect: 100-continue");
+  if (!tmp) {
+    goto test_cleanup;
+  }
+  hhl = tmp;
 
   test_setopt(curl, CURLOPT_URL, URL);
   test_setopt(curl, CURLOPT_PROXY, libtest_arg2);