Skip to content

Commit

Permalink
out_tcp: check connection first (fluent#6208)
Browse files Browse the repository at this point in the history
compose_payload allocates memory when 'format' is not 'msgpack'.
It is not released when no connection is available and it causes issue fluent#6208.

This patch is to change flush flow.

1. Check connection
2. Invoke compose_payload

Signed-off-by: Takahiro Yamashita <[email protected]>
Signed-off-by: root <[email protected]>
  • Loading branch information
nokute78 authored and root committed Feb 8, 2023
1 parent 8bee4e5 commit 26d8d5c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions plugins/out_tcp/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,6 @@ static void cb_tcp_flush(struct flb_event_chunk *event_chunk,
size_t out_size = 0;
(void) i_ins;

ret = compose_payload(ctx, event_chunk->data, event_chunk->size,
&out_payload, &out_size);
if (ret != FLB_OK) {
return FLB_OUTPUT_RETURN(ret);
}

/* Get upstream context and connection */
u = ctx->u;
u_conn = flb_upstream_conn_get(u);
Expand All @@ -109,6 +103,13 @@ static void cb_tcp_flush(struct flb_event_chunk *event_chunk,
FLB_OUTPUT_RETURN(FLB_RETRY);
}

ret = compose_payload(ctx, event_chunk->data, event_chunk->size,
&out_payload, &out_size);
if (ret != FLB_OK) {
flb_upstream_conn_release(u_conn);
return FLB_OUTPUT_RETURN(ret);
}

if (ctx->out_format == FLB_PACK_JSON_FORMAT_NONE) {
ret = flb_io_net_write(u_conn,
event_chunk->data, event_chunk->size,
Expand Down

0 comments on commit 26d8d5c

Please sign in to comment.