diff options
author | Daniel Stenberg <daniel@haxx.se> | 2009-11-23 13:56:45 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2009-11-23 13:56:45 +0000 |
commit | 1fddcb3f887c487a22b38082e651d24ae5865db2 (patch) | |
tree | 6a8d13da24e0dc3e22382940b07d1f5a8193e537 /src | |
parent | b723500af0d52a4ae919e6f196efa8fbdd1bd783 (diff) |
- Bjorn Augustsson reported a bug which made curl not report any problems even
though it failed to write a very small download to disk (done in a single
fwrite call). It turned out to be because fwrite() returned success, but
there was insufficient error-checking for the fclose() call which tricked
curl to believe things were fine.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c index fed1e1fcc..b9ac7adb4 100644 --- a/src/main.c +++ b/src/main.c @@ -3316,9 +3316,15 @@ static size_t my_fwrite(void *buffer, size_t sz, size_t nmemb, void *stream) curl_easy_pause(config->easy, CURLPAUSE_CONT); } - if(config->nobuffer) + if(config->nobuffer) { /* disable output buffering */ - fflush(out->stream); + rc = fflush(out->stream); + if(rc) { + /* return a value that isn't the same as sz * nmemb */ + rc = (0 == (sz * nmemb)) ? 1 : 0; + return rc; /* failure */ + } + } return rc; } @@ -5170,8 +5176,14 @@ show_error: } } - if (outfile && !curlx_strequal(outfile, "-") && outs.stream) - fclose(outs.stream); + if (outfile && !curlx_strequal(outfile, "-") && outs.stream) { + int rc = fclose(outs.stream); + if(!res && rc) { + /* something went wrong in the writing process */ + res = CURLE_WRITE_ERROR; + fprintf(config->errors, "(%s) Failed writing body\n", res); + } + } #ifdef HAVE_UTIME /* Important that we set the time _after_ the file has been |