提交 40fd7c1f 编写于 作者: D Daniel Gustafsson 提交者: Francisco Guerrero

Avoid zeroing out memory when not required

The only time the internal buffer cleanup code was called was just
before freeing the entire context, so individually zeroing out the
members is pointless. Remove the function entirely and inline the
buffer freeing into the context cleanup codepath.

For zeroing the error buffer, it's only called right after allocating
the error buffer with palloc0() in the first place so the memory will
always be zeroed out when reaching here.
Reviewed-by: NFrancisco Guerrero <aguerrero@pivotal.io>
上级 ff62bb4d
......@@ -103,7 +103,6 @@ static void enlarge_internal_buffer(churl_buffer *buffer, size_t required);
static void finish_upload(churl_context *context);
static void cleanup_curl_handle(churl_context *context);
static void multi_remove_handle(churl_context *context);
static void cleanup_internal_buffer(churl_buffer *buffer);
static void churl_cleanup_context(churl_context *context);
static size_t write_callback(char *buffer, size_t size, size_t nitems, void *userp);
static void fill_internal_buffer(churl_context *context, int want);
......@@ -111,7 +110,6 @@ static void churl_headers_set(churl_context *context, CHURL_HEADERS settings);
static void check_response_status(churl_context *context);
static void check_response_code(churl_context *context);
static void check_response(churl_context *context);
static void clear_error_buffer(churl_context *context);
static size_t header_callback(char *buffer, size_t size, size_t nitems, void *userp);
static void free_http_response(churl_context *context);
static void compact_internal_buffer(churl_buffer *buffer);
......@@ -316,7 +314,6 @@ churl_init(const char *url, CHURL_HEADERS headers)
churl_context *context = churl_new_context();
create_curl_handle(context);
clear_error_buffer(context);
/* Required for resolving localhost on some docker environments that
* had intermittent networking issues when using pxf on HAWQ
......@@ -488,8 +485,6 @@ churl_cleanup(CHURL_HANDLE handle, bool after_error)
}
cleanup_curl_handle(context);
cleanup_internal_buffer(context->download_buffer);
cleanup_internal_buffer(context->upload_buffer);
churl_cleanup_context(context);
}
......@@ -503,14 +498,6 @@ churl_new_context()
return context;
}
static void
clear_error_buffer(churl_context *context)
{
if (!context)
return;
context->curl_error_buffer[0] = 0;
}
static void
create_curl_handle(churl_context *context)
{
......@@ -701,28 +688,23 @@ multi_remove_handle(churl_context *context)
curl_error, curl_easy_strerror(curl_error));
}
static void
cleanup_internal_buffer(churl_buffer *buffer)
{
if ((buffer) && (buffer->ptr))
{
pfree(buffer->ptr);
buffer->ptr = NULL;
buffer->bot = 0;
buffer->top = 0;
buffer->max = 0;
}
}
static void
churl_cleanup_context(churl_context *context)
{
if (context)
{
if (context->download_buffer)
{
if (context->download_buffer->ptr)
pfree(context->download_buffer->ptr);
pfree(context->download_buffer);
}
if (context->upload_buffer)
{
if (context->upload_buffer->ptr)
pfree(context->upload_buffer->ptr);
pfree(context->upload_buffer);
}
pfree(context);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册