Skip to content

Commit

Permalink
tests: runtime: core_chunk_trace: Check callback struct member's valu…
Browse files Browse the repository at this point in the history
…es strictly

Without this check, the following weird error is occurred
intermittently:

```log
[0] dummy.0: [1664938706.407551000, {"message"=>"dummy"}]
[2022/10/05 11:58:27] [ info] [test] flush record
flb-rt-core_chunk_trace(32205,0x16fe87000) malloc: *** error for object 0x600002600074: pointer being realloc'd was not allocated
flb-rt-core_chunk_trace(32205,0x16fe87000) malloc: *** set a breakpoint in malloc_error_break to debug
```

The main reason is, num_records index is broken in some cases:

```
flb-rt-core_chunk_trace(32205,0x16fe87000) malloc: *** error for object 0x600002600074: pointer being realloc'd was not allocated
flb-rt-core_chunk_trace(32205,0x16fe87000) malloc: *** set a breakpoint in malloc_error_break to debug
[2022/10/05 11:58:27] [ info] [input] pausing dummy.0
Process 32205 stopped
* thread #2, name = 'flb-pipeline', stop reason = breakpoint 1.1
    frame #0: 0x00000001b34a3120 libsystem_malloc.dylib`malloc_error_break
libsystem_malloc.dylib`malloc_error_break:
->  0x1b34a3120 <+0>:  pacibsp
    0x1b34a3124 <+4>:  stp    x29, x30, [sp, #-0x10]!
    0x1b34a3128 <+8>:  mov    x29, sp
    0x1b34a312c <+12>: nop
Target 0: (flb-rt-core_chunk_trace) stopped.
(lldb) bt
* thread #2, name = 'flb-pipeline', stop reason = breakpoint 1.1
  * frame #0: 0x00000001b34a3120 libsystem_malloc.dylib`malloc_error_break
    frame #1: 0x00000001b3494844 libsystem_malloc.dylib`malloc_vreport + 428
    frame #2: 0x00000001b3497f34 libsystem_malloc.dylib`malloc_report + 64
    frame #3: 0x00000001b3488210 libsystem_malloc.dylib`realloc + 328
    frame #4: 0x0000000100006154 flb-rt-core_chunk_trace`flb_realloc(ptr=0x0000600002600074, size=18446744064764412176) at flb_mem.h:94:12
    frame #5: 0x0000000100005fc8 flb-rt-core_chunk_trace`callback_add_record(data=0x0000600003014000, size=135, cb_data=0x0000600000004010) at core_chunk_trace.c:51:28
    frame #6: 0x00000001001268b0 flb-rt-core_chunk_trace`out_lib_flush(event_chunk=0x0000600000c14000, out_flush=0x0000600001714000, i_ins=0x0000000100b09ab0, out_context=0x0000600000204a80, config=0x000000010181d200) at out_lib.c:197:9
    frame #7: 0x0000000100029d70 flb-rt-core_chunk_trace`output_pre_cb_flush at flb_output.h:517:5
    frame #8: 0x000000010044fa64 flb-rt-core_chunk_trace`co_switch(handle=0x000000010044fa64) at aarch64.c:133:4
(lldb) frane select 5
error: 'frane' is not a valid command.
(lldb) frame select 5
frame #5: 0x0000000100005fc8 flb-rt-core_chunk_trace`callback_add_record(data=0x0000600003014000, size=135, cb_data=0x0000600000004010) at core_chunk_trace.c:51:28
   48  	                           flb_calloc(1, sizeof(struct callback_record));
   49  	        } else {
   50  	            ctx->records = (struct callback_record *)
-> 51  	                           flb_realloc(ctx->records,
   52  	                                       (ctx->num_records+1)*sizeof(struct callback_record));
   53  	        }
   54  	        if (ctx->records ==  NULL) {
(lldb) po ctx->records
0x0000600002600074

(lldb) po ctx->records
0x0000600002600074

(lldb) po ctx->num_records
-559071216
```

Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Oct 5, 2022
1 parent d0f8d8b commit fb18754
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tests/runtime/core_chunk_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ int callback_add_record(void* data, size_t size, void* cb_data)

if (size > 0) {
flb_info("[test] flush record");
if (ctx->records == NULL) {
/* We should check ctx->records and ctx->num_records have
* valid values. */
if (ctx->records == NULL || ctx->num_records < 0) {
ctx->records = (struct callback_record *)
flb_calloc(1, sizeof(struct callback_record));
} else {
Expand Down

0 comments on commit fb18754

Please sign in to comment.