Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in_elasticsearch: fixed memory leak (CID 507822) #9359

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions plugins/in_elasticsearch/in_elasticsearch_bulk_prot.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ int in_elasticsearch_bulk_prot_handle(struct flb_in_elasticsearch *ctx,
if (ctx->ins->tag && !ctx->ins->tag_default) {
tag = flb_sds_create(ctx->ins->tag);
if (tag == NULL) {
mk_mem_free(uri);
return -1;
}
}
Expand Down Expand Up @@ -925,8 +926,8 @@ int in_elasticsearch_bulk_prot_handle_error(struct flb_in_elasticsearch *ctx,


/* New gen HTTP server */
static int send_response_ng(struct flb_http_response *response,
int http_status,
static int send_response_ng(struct flb_http_response *response,
int http_status,
char *content_type,
char *message)
{
Expand All @@ -946,14 +947,14 @@ static int send_response_ng(struct flb_http_response *response,
}

if (content_type != NULL) {
flb_http_response_set_header(response,
flb_http_response_set_header(response,
"content-type", 0,
content_type, 0);
}

if (message != NULL) {
flb_http_response_set_body(response,
(unsigned char *) message,
flb_http_response_set_body(response,
(unsigned char *) message,
strlen(message));
}

Expand All @@ -962,14 +963,14 @@ static int send_response_ng(struct flb_http_response *response,
return 0;
}

static int send_json_response_ng(struct flb_http_response *response,
static int send_json_response_ng(struct flb_http_response *response,
int http_status,
char *message)
{
return send_response_ng(response, http_status, "application/json", message);
return send_response_ng(response, http_status, "application/json", message);
}

static int send_version_message_response_ng(struct flb_http_response *response,
static int send_version_message_response_ng(struct flb_http_response *response,
struct flb_in_elasticsearch *ctx,
int http_status)
{
Expand All @@ -989,14 +990,14 @@ static int send_version_message_response_ng(struct flb_http_response *response,
ES_VERSION_RESPONSE_TEMPLATE,
ctx->es_version);

send_json_response_ng(response, http_status, message);
send_json_response_ng(response, http_status, message);

cfl_sds_destroy(message);

return 0;
}

static int send_dummy_sniffer_response_ng(struct flb_http_response *response,
static int send_dummy_sniffer_response_ng(struct flb_http_response *response,
struct flb_in_elasticsearch *ctx,
int http_status)
{
Expand Down Expand Up @@ -1024,7 +1025,7 @@ static int send_dummy_sniffer_response_ng(struct flb_http_response *response,
ctx->cluster_name, ctx->node_name,
hostname, ctx->tcp_port, ctx->buffer_max_size);

send_json_response_ng(response, http_status, resp);
send_json_response_ng(response, http_status, resp);

flb_sds_destroy(resp);

Expand Down Expand Up @@ -1081,7 +1082,7 @@ int in_elasticsearch_bulk_prot_handle_ng(struct flb_http_request *request,
}

/* HTTP/1.1 needs Host header */
if (request->protocol_version == HTTP_PROTOCOL_HTTP1 &&
if (request->protocol_version == HTTP_PROTOCOL_HTTP1 &&
request->host == NULL) {

return -1;
Expand Down Expand Up @@ -1113,7 +1114,7 @@ int in_elasticsearch_bulk_prot_handle_ng(struct flb_http_request *request,
else if (request->method == HTTP_METHOD_POST) {
if (strcmp(request->path, "/_bulk") == 0) {
bulk_statuses = flb_sds_create_size(context->buffer_max_size);

if (bulk_statuses == NULL) {
return -1;
}
Expand Down Expand Up @@ -1159,7 +1160,7 @@ int in_elasticsearch_bulk_prot_handle_ng(struct flb_http_request *request,

flb_sds_destroy(bulk_statuses);
flb_sds_destroy(bulk_response);

} else {
send_response_ng(response, 400, NULL, "error: invalid HTTP endpoint\n");

Expand All @@ -1171,6 +1172,6 @@ int in_elasticsearch_bulk_prot_handle_ng(struct flb_http_request *request,

return -1;
}

return 0;
}
Loading