curl_formget: fix FILE * leak

Properly deal with the fact that the last fread() call most probably is
a short read, and when using callbacks in fact all calls can be short
reads. No longer consider a file read done until it returns a 0 from the
read function.

Reported by: Aaron Orenstein
Bug: http://curl.haxx.se/mail/lib-2011-06/0048.html
This commit is contained in:
Daniel Stenberg 2011-06-13 22:32:00 +02:00
parent 85881f9f35
commit 0aedccc18a
3 changed files with 28 additions and 3 deletions

View file

@ -23,6 +23,9 @@ formpost unit tests
<tool>
unit1308
</tool>
<file name="log/test-1308">
Piece of the file that is to uploaded as a formpost
</file>
</client>
</testcase>

View file

@ -75,4 +75,21 @@ UNITTEST_START
curl_formfree(post);
/* start a new formpost with a file upload and formget */
post = last = NULL;
rc = curl_formadd(&post, &last,
CURLFORM_PTRNAME, "name of file field",
CURLFORM_FILE, "log/test-1308",
CURLFORM_FILENAME, "custom named file",
CURLFORM_END);
fail_unless(rc == 0, "curl_formadd returned error");
rc = curl_formget(post, &total_size, print_httppost_callback);
fail_unless(rc == 0, "curl_formget returned error");
fail_unless(total_size == 847, "curl_formget got wrong size back");
curl_formfree(post);
UNITTEST_STOP