Changeset: a41f0d53858a for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a41f0d53858a
Modified Files:
        common/stream/stream.c
Branch: Jul2012
Log Message:

curl streams: When reallocing, use correct value to realloc to.
We have a "maxsize" value which is supposed to be the size we've
allocated.  Use it, also in realloc.
Also, realloc may fail, but the buffer is then still allocated.  Deal
with that.
(transplanted from aefeb465071e4573cffbc02889336e7300e23369)


diffs (26 lines):

diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -1145,7 +1145,7 @@ struct curl_data {
 static struct curl_data *curl_handles;
 #endif
 
-#define BLOCK_CURL     8192
+#define BLOCK_CURL     (1 << 16)
 
 /* this function is called by libcurl when there is data for us */
 static size_t
@@ -1174,8 +1174,12 @@ write_callback(char *buffer, size_t size
 #endif
        /* allocate more buffer space if we still don't have enough space */
        if (c->maxsize - c->usesize < size) {
+               char *b;
                c->maxsize = (c->usesize + size + BLOCK_CURL - 1) & 
~(BLOCK_CURL - 1);
-               c->buffer = realloc(c->buffer, c->usesize + size);
+               b = realloc(c->buffer, c->maxsize);
+               if (b == NULL)
+                       return 0; /* indicate failure to library */
+               c->buffer = b;
        }
        /* finally, store the data we received */
        memcpy(c->buffer + c->usesize, buffer, size);
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to