]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: properly free mimepost data
authorDaniel Stenberg <daniel@haxx.se>
Sat, 4 Jan 2020 20:40:49 +0000 (21:40 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 4 Jan 2020 22:06:44 +0000 (23:06 +0100)
... as it could otherwise leak memory when a transfer failed.

Added test 1293 to verify.

Reported-by: Brian Carpenter
Fixes #4781
Closes #4782

src/tool_operate.c
tests/data/Makefile.inc
tests/data/test1293 [new file with mode: 0644]

index 9dc59b2e9ba4f7906847d2119e0e9bb8d25a89e8..2bee9349a621320399ca1982057475b921c8bf86 100644 (file)
@@ -1357,6 +1357,9 @@ static CURLcode single_transfer(struct GlobalConfig *global,
                     config->postfieldsize);
           break;
         case HTTPREQ_MIMEPOST:
+          /* free previous remainders */
+          curl_mime_free(config->mimepost);
+          config->mimepost = NULL;
           result = tool2curlmime(curl, config->mimeroot, &config->mimepost);
           if(result)
             break;
index 5e93b089d01235700f153c6145d1a586132f07ad..edfa61b0ea434497addb0697d7a03bc5e046b96a 100644 (file)
@@ -5,7 +5,7 @@
 #                            | (__| |_| |  _ <| |___
 #                             \___|\___/|_| \_\_____|
 #
-# Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
+# Copyright (C) 1998 - 2020, 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
@@ -146,7 +146,7 @@ test1260 test1261 test1262 test1263 test1264 test1265 test1266 test1267 \
 test1268 test1269 test1270 \
 \
 test1280 test1281 test1282 test1283 test1284 test1285 test1286 test1287 \
-test1288 test1289 test1290 test1291 test1292 \
+test1288 test1289 test1290 test1291 test1292 test1293 \
 test1298 test1299 \
 test1300 test1301 test1302 test1303 test1304 test1305 test1306 test1307 \
 test1308 test1309 test1310 test1311 test1312 test1313 test1314 test1315 \
diff --git a/tests/data/test1293 b/tests/data/test1293
new file mode 100644 (file)
index 0000000..11a28a3
--- /dev/null
@@ -0,0 +1,67 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+-F
+</keywords>
+</info>
+
+#
+# Server-side
+<reply>
+<data nocheck="yes">
+HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT
+ETag: "21025-dc7-39462498"
+Accept-Ranges: bytes
+Content-Length: 6
+Connection: close
+Content-Type: text/html
+Funny-head: yesyes
+
+-foo-
+</data>
+</reply>
+
+#
+# Client-side
+<client>
+<server>
+http
+</server>
+ <name>
+Multipart formpost to two URLs, the first failing
+ </name>
+ <command>
+http://0 http://%HOSTIP:%HTTPPORT/1293 -F=
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<strip>
+^User-Agent:.*
+</strip>
+<strippart>
+s/^--------------------------[a-z0-9]*/------------------------------/
+s/boundary=------------------------[a-z0-9]*/boundary=----------------------------/
+</strippart>
+<protocol>
+POST /1293 HTTP/1.1\r
+Host: 127.0.0.1:8990\r
+Accept: */*\r
+Content-Length: 126\r
+Content-Type: multipart/form-data; boundary=----------------------------\r
+\r
+------------------------------\r
+Content-Disposition: form-data\r
+\r
+\r
+--------------------------------\r
+</protocol>
+</verify>
+</testcase>