Skip to content

Commit 5119644

Browse files
leonardo-albertovichedsiper
authored andcommitted
log_event_decoder: fixed corner case that caused double free
When a single event was read and the unpacked record data was copied to the unpacked group record structure it would cause a double free when destroying the decoder. To handle this we need to ensure that the zone pointers in those instances do not match or otherwise re-initialize one to avoid performing the spurious free. Signed-off-by: Leonardo Alminana <[email protected]>
1 parent c19e57b commit 5119644

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/flb_log_event_decoder.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ void flb_log_event_decoder_destroy(struct flb_log_event_decoder *context)
146146

147147
if (context != NULL) {
148148
if (context->initialized) {
149+
if (context->unpacked_group_record.zone ==
150+
context->unpacked_event.zone) {
151+
msgpack_unpacked_init(&context->unpacked_event);
152+
}
153+
149154
msgpack_unpacked_destroy(&context->unpacked_group_record);
150155
msgpack_unpacked_destroy(&context->unpacked_empty_map);
151156
msgpack_unpacked_destroy(&context->unpacked_event);
@@ -322,6 +327,11 @@ int flb_log_event_decoder_next(struct flb_log_event_decoder *context,
322327
return context->last_result;
323328
}
324329

330+
if (context->unpacked_group_record.zone ==
331+
context->unpacked_event.zone) {
332+
msgpack_unpacked_init(&context->unpacked_event);
333+
}
334+
325335
previous_offset = context->offset;
326336
result = msgpack_unpack_next(&context->unpacked_event,
327337
context->buffer,
@@ -377,8 +387,6 @@ int flb_log_event_decoder_next(struct flb_log_event_decoder *context,
377387
}
378388

379389
if (context->read_groups != FLB_TRUE) {
380-
msgpack_unpacked_init(&context->unpacked_event);
381-
382390
memset(event, 0, sizeof(struct flb_log_event));
383391

384392
return flb_log_event_decoder_next(context, event);

0 commit comments

Comments
 (0)