]> granicus.if.org Git - curl/commitdiff
Curl_pgrsDone: return int and acknowledge return code
authorDaniel Stenberg <daniel@haxx.se>
Sun, 10 Jun 2012 21:39:04 +0000 (23:39 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 10 Jun 2012 21:40:35 +0000 (23:40 +0200)
Since Curl_pgrsDone() itself calls Curl_pgrsUpdate() which may return an
abort instruction or similar we need to return that info back and
subsequently properly handle return codes from Curl_pgrsDone() where
used.

(Spotted by a Coverity scan)

lib/progress.c
lib/progress.h
lib/ssh.c
lib/tftp.c
lib/url.c

index 4c9a63acbbc4bdefc24de602efceee48245cefe3..e73f01811b3d1bb636155a10c12bbfe75a372cf4 100644 (file)
@@ -131,11 +131,14 @@ static char *max5data(curl_off_t bytes, char *max5)
 
 */
 
-void Curl_pgrsDone(struct connectdata *conn)
+int Curl_pgrsDone(struct connectdata *conn)
 {
+  int rc;
   struct SessionHandle *data = conn->data;
   data->progress.lastshow=0;
-  Curl_pgrsUpdate(conn); /* the final (forced) update */
+  rc = Curl_pgrsUpdate(conn); /* the final (forced) update */
+  if(rc)
+    return rc;
 
   if(!(data->progress.flags & PGRS_HIDE) &&
      !data->progress.callback)
@@ -144,6 +147,7 @@ void Curl_pgrsDone(struct connectdata *conn)
     fprintf(data->set.err, "\n");
 
   data->progress.speeder_c = 0; /* reset the progress meter display */
+  return 0;
 }
 
 /* reset all times except redirect, and reset the known transfer sizes */
@@ -241,6 +245,10 @@ void Curl_pgrsSetUploadSize(struct SessionHandle *data, curl_off_t size)
     data->progress.flags &= ~PGRS_UL_SIZE_KNOWN;
 }
 
+/*
+ * Curl_pgrsUpdate() returns 0 for success or the value returned by the
+ * progress callback!
+ */
 int Curl_pgrsUpdate(struct connectdata *conn)
 {
   struct timeval now;
index a41d5f92ff85f3eef6888e212fd5c022f4704cfe..951de7f9465d7fcf6258e0280112b925273a0278 100644 (file)
@@ -39,7 +39,7 @@ typedef enum {
   TIMER_LAST /* must be last */
 } timerid;
 
-void Curl_pgrsDone(struct connectdata *);
+int Curl_pgrsDone(struct connectdata *);
 void Curl_pgrsStartNow(struct SessionHandle *data);
 void Curl_pgrsSetDownloadSize(struct SessionHandle *data, curl_off_t size);
 void Curl_pgrsSetUploadSize(struct SessionHandle *data, curl_off_t size);
index 90c8013c2123f924a2ced3eaa6772698a808d9b8..a1abc5b08d94a461dfef73d6b8e42d9204cd6335 100644 (file)
--- a/lib/ssh.c
+++ b/lib/ssh.c
@@ -2820,7 +2820,8 @@ static CURLcode ssh_done(struct connectdata *conn, CURLcode status)
 
   if(sftp_scp)
     Curl_safefree(sftp_scp->path);
-  Curl_pgrsDone(conn);
+  if(Curl_pgrsDone(conn))
+    return CURLE_ABORTED_BY_CALLBACK;
 
   conn->data->req.keepon = 0; /* clear all bits */
   return result;
index 85404de8b4641460996049bb50f6d85ff428e1f4..7202b94d37824ac2972d3a59d9b9d9bf65fe995d 100644 (file)
@@ -1036,7 +1036,8 @@ static CURLcode tftp_done(struct connectdata *conn, CURLcode status,
   (void)status; /* unused */
   (void)premature; /* not used */
 
-  Curl_pgrsDone(conn);
+  if(Curl_pgrsDone(conn))
+    return CURLE_ABORTED_BY_CALLBACK;
 
   /* If we have encountered an error */
   code = tftp_translate_code(state->error);
index b78c200fa058c087a656da4d82695427f1309130..88e169c98e87687fd5695d0c8eb4e85fac6cf142 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -5379,7 +5379,8 @@ CURLcode Curl_done(struct connectdata **connp,
   else
     result = CURLE_OK;
 
-  Curl_pgrsDone(conn); /* done with the operation */
+  if(Curl_pgrsDone(conn) && !result)
+    result = CURLE_ABORTED_BY_CALLBACK;
 
   /* if the transfer was completed in a paused state there can be buffered
      data left to write and then kill */