Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Curl_pgrsDone: return int and acknowledge return code

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)
  • Loading branch information...
commit 6cd084a3b5129d9ab8db3e5bc0f094943d7eef89 1 parent 72c7c1d
Daniel Stenberg authored June 10, 2012
12  lib/progress.c
@@ -131,11 +131,14 @@ static char *max5data(curl_off_t bytes, char *max5)
131 131
 
132 132
 */
133 133
 
134  
-void Curl_pgrsDone(struct connectdata *conn)
  134
+int Curl_pgrsDone(struct connectdata *conn)
135 135
 {
  136
+  int rc;
136 137
   struct SessionHandle *data = conn->data;
137 138
   data->progress.lastshow=0;
138  
-  Curl_pgrsUpdate(conn); /* the final (forced) update */
  139
+  rc = Curl_pgrsUpdate(conn); /* the final (forced) update */
  140
+  if(rc)
  141
+    return rc;
139 142
 
140 143
   if(!(data->progress.flags & PGRS_HIDE) &&
141 144
      !data->progress.callback)
@@ -144,6 +147,7 @@ void Curl_pgrsDone(struct connectdata *conn)
144 147
     fprintf(data->set.err, "\n");
145 148
 
146 149
   data->progress.speeder_c = 0; /* reset the progress meter display */
  150
+  return 0;
147 151
 }
148 152
 
149 153
 /* 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)
241 245
     data->progress.flags &= ~PGRS_UL_SIZE_KNOWN;
242 246
 }
243 247
 
  248
+/*
  249
+ * Curl_pgrsUpdate() returns 0 for success or the value returned by the
  250
+ * progress callback!
  251
+ */
244 252
 int Curl_pgrsUpdate(struct connectdata *conn)
245 253
 {
246 254
   struct timeval now;
2  lib/progress.h
@@ -39,7 +39,7 @@ typedef enum {
39 39
   TIMER_LAST /* must be last */
40 40
 } timerid;
41 41
 
42  
-void Curl_pgrsDone(struct connectdata *);
  42
+int Curl_pgrsDone(struct connectdata *);
43 43
 void Curl_pgrsStartNow(struct SessionHandle *data);
44 44
 void Curl_pgrsSetDownloadSize(struct SessionHandle *data, curl_off_t size);
45 45
 void Curl_pgrsSetUploadSize(struct SessionHandle *data, curl_off_t size);
3  lib/ssh.c
@@ -2820,7 +2820,8 @@ static CURLcode ssh_done(struct connectdata *conn, CURLcode status)
2820 2820
 
2821 2821
   if(sftp_scp)
2822 2822
     Curl_safefree(sftp_scp->path);
2823  
-  Curl_pgrsDone(conn);
  2823
+  if(Curl_pgrsDone(conn))
  2824
+    return CURLE_ABORTED_BY_CALLBACK;
2824 2825
 
2825 2826
   conn->data->req.keepon = 0; /* clear all bits */
2826 2827
   return result;
3  lib/tftp.c
@@ -1036,7 +1036,8 @@ static CURLcode tftp_done(struct connectdata *conn, CURLcode status,
1036 1036
   (void)status; /* unused */
1037 1037
   (void)premature; /* not used */
1038 1038
 
1039  
-  Curl_pgrsDone(conn);
  1039
+  if(Curl_pgrsDone(conn))
  1040
+    return CURLE_ABORTED_BY_CALLBACK;
1040 1041
 
1041 1042
   /* If we have encountered an error */
1042 1043
   code = tftp_translate_code(state->error);
3  lib/url.c
@@ -5379,7 +5379,8 @@ CURLcode Curl_done(struct connectdata **connp,
5379 5379
   else
5380 5380
     result = CURLE_OK;
5381 5381
 
5382  
-  Curl_pgrsDone(conn); /* done with the operation */
  5382
+  if(Curl_pgrsDone(conn) && !result)
  5383
+    result = CURLE_ABORTED_BY_CALLBACK;
5383 5384
 
5384 5385
   /* if the transfer was completed in a paused state there can be buffered
5385 5386
      data left to write and then kill */

0 notes on commit 6cd084a

Please sign in to comment.
Something went wrong with that request. Please try again.