Github user interma commented on a diff in the pull request:
https://github.com/apache/incubator-hawq/pull/1079#discussion_r95508628
--- Diff: src/backend/libpq/rangerrest.c ---
@@ -281,29 +283,27 @@ static size_t write_callback(char *contents, size_t
size, size_t nitems,
CURL_HANDLE curl = (CURL_HANDLE) userp;
Assert(curl != NULL);
- if (curl->response.buffer == NULL)
- {
- curl->response.buffer = palloc0(realsize + 1);
- }
- else
+ elog(DEBUG3, "response size is %d. response buffer size is %d.",
curl->response.size, curl->response.buffer_size);
+ if(curl->response.size + realsize >= curl->response.buffer_size)
{
- /*Note:*/
- /*our repalloc is not same as realloc, repalloc's first
param(buffer) can not be NULL*/
- curl->response.buffer = repalloc(curl->response.buffer,
curl->response.size + realsize + 1);
+ /*
+ * our repalloc is not same as realloc, repalloc's first
param(buffer) can not be NULL
+ * double the buffer size if the buffer is not enough.
+ */
+ curl->response.buffer = repalloc(curl->response.buffer,
curl->response.buffer_size * 2);
--- End diff --
Oh, buffer*2 maybe not enough for current content.
Should use a loop to determine the next buffer_size:
```
while (curl->response.size + realsize >= curl->response.buffer_size)
{ curl->response.buffer_size *= 2; }
//do realloc
//...
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---