Skip to content

Conversation

@nokute78
Copy link
Collaborator

This patch is to fix following valgrind error.

==20919== 
==20919== HEAP SUMMARY:
==20919==     in use at exit: 7 bytes in 1 blocks
==20919==   total heap usage: 1,572 allocs, 1,571 frees, 968,794 bytes allocated
==20919== 
==20919== 7 bytes in 1 blocks are still reachable in loss record 1 of 1
==20919==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==20919==    by 0x18E880: flb_malloc (flb_mem.h:80)
==20919==    by 0x18EB6A: flb_strndup (flb_str.h:34)
==20919==    by 0x18EBD1: flb_strdup (flb_str.h:46)
==20919==    by 0x1912B7: flb_main (fluent-bit.c:949)
==20919==    by 0x192012: main (fluent-bit.c:1375)
==20919== 
==20919== LEAK SUMMARY:
==20919==    definitely lost: 0 bytes in 0 blocks
==20919==    indirectly lost: 0 bytes in 0 blocks
==20919==      possibly lost: 0 bytes in 0 blocks
==20919==    still reachable: 7 bytes in 1 blocks
==20919==         suppressed: 0 bytes in 0 blocks
==20919== 
==20919== For lists of detected and suppressed errors, rerun with: -s
==20919== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

This is a leak of trace_output

char *trace_output = flb_strdup("stdout");

It should be released here. But it isn't.

fluent-bit/src/fluent-bit.c

Lines 1359 to 1361 in 824ba3d

if (trace_output) {
flb_free(trace_output);
}

This is caused by flb_signal_exit. It calls _exit.

This patch is to cleanup flb_signal_exit.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • [N/A] Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • [N/A] Run local packaging test showing all targets (including any new ones) build.
  • [N/A] Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • [N/A] Documentation required for this feature

Backporting

  • [N/A] Backport to latest stable release.

Debug/Valgrind output

$ valgrind --leak-check=full --show-leak-kinds=all bin/fluent-bit -i cpu -o stdout
==22743== Memcheck, a memory error detector
==22743== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==22743== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==22743== Command: bin/fluent-bit -i cpu -o stdout
==22743== 
Fluent Bit v2.1.8
* Copyright (C) 2015-2022 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

[2023/07/22 07:45:31] [ info] [fluent bit] version=2.1.8, commit=824ba3dd08, pid=22743
[2023/07/22 07:45:31] [ info] [storage] ver=1.2.0, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2023/07/22 07:45:31] [ info] [cmetrics] version=0.6.3
[2023/07/22 07:45:31] [ info] [ctraces ] version=0.3.1
[2023/07/22 07:45:31] [ info] [input:cpu:cpu.0] initializing
[2023/07/22 07:45:31] [ info] [input:cpu:cpu.0] storage_strategy='memory' (memory only)
[2023/07/22 07:45:31] [ info] [sp] stream processor started
[2023/07/22 07:45:31] [ info] [output:stdout:stdout.0] worker #0 started
[0] cpu.0: [[1689979532.658521026, {}], {"cpu_p"=>30.000000, "user_p"=>29.000000, "system_p"=>1.000000, "cpu0.p_cpu"=>30.000000, "cpu0.p_user"=>29.000000, "cpu0.p_system"=>1.000000}]
^C[2023/07/22 07:45:34] [engine] caught signal (SIGINT)
[0] cpu.0: [[1689979533.675362867, {}], {"cpu_p"=>17.000000, "user_p"=>17.000000, "system_p"=>0.000000, "cpu0.p_cpu"=>17.000000, "cpu0.p_user"=>17.000000, "cpu0.p_system"=>0.000000}]
[2023/07/22 07:45:34] [ warn] [engine] service will shutdown in max 5 seconds
[2023/07/22 07:45:34] [ info] [input] pausing cpu.0
[2023/07/22 07:45:34] [ info] [engine] service has stopped (0 pending tasks)
[2023/07/22 07:45:34] [ info] [input] pausing cpu.0
[2023/07/22 07:45:34] [ info] [output:stdout:stdout.0] thread worker #0 stopping...
[2023/07/22 07:45:34] [ info] [output:stdout:stdout.0] thread worker #0 stopped
==22743== 
==22743== HEAP SUMMARY:
==22743==     in use at exit: 0 bytes in 0 blocks
==22743==   total heap usage: 1,572 allocs, 1,572 frees, 968,794 bytes allocated
==22743== 
==22743== All heap blocks were freed -- no leaks are possible
==22743== 
==22743== For lists of detected and suppressed errors, rerun with: -s
==22743== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

@nokute78 nokute78 temporarily deployed to pr July 21, 2023 22:46 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr July 21, 2023 22:46 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr July 21, 2023 22:46 — with GitHub Actions Inactive
Comment on lines -563 to -567
if (cf_opts != NULL) {
flb_cf_destroy(cf_opts);
}
flb_stop(ctx);
flb_destroy(ctx);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions will be called

fluent-bit/src/fluent-bit.c

Lines 1348 to 1352 in 824ba3d

cf_opts = flb_cf_context_get();
if (cf_opts != NULL) {
flb_cf_destroy(cf_opts);
}

and

fluent-bit/src/fluent-bit.c

Lines 1364 to 1365 in 824ba3d

flb_stop(ctx);
flb_destroy(ctx);

@nokute78 nokute78 temporarily deployed to pr July 21, 2023 23:12 — with GitHub Actions Inactive
Signed-off-by: Takahiro Yamashita <[email protected]>
@nokute78 nokute78 temporarily deployed to pr July 21, 2023 23:58 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr July 21, 2023 23:58 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr July 21, 2023 23:58 — with GitHub Actions Inactive
@nokute78
Copy link
Collaborator Author

This patch is also to release trace_props.

$ valgrind --leak-check=full --show-leak-kinds=all bin/fluent-bit -i cpu -o stdout --trace-output-property=key=val
==35254== Memcheck, a memory error detector
==35254== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==35254== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==35254== Command: bin/fluent-bit -i cpu -o stdout --trace-output-property=key=val
==35254== 
Fluent Bit v2.1.8
* Copyright (C) 2015-2022 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

[2023/07/22 08:59:11] [ info] [fluent bit] version=2.1.8, commit=824ba3dd08, pid=35254
[2023/07/22 08:59:11] [ info] [storage] ver=1.2.0, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2023/07/22 08:59:11] [ info] [cmetrics] version=0.6.3
[2023/07/22 08:59:11] [ info] [ctraces ] version=0.3.1
[2023/07/22 08:59:12] [ info] [input:cpu:cpu.0] initializing
[2023/07/22 08:59:12] [ info] [input:cpu:cpu.0] storage_strategy='memory' (memory only)
[2023/07/22 08:59:12] [ info] [sp] stream processor started
[2023/07/22 08:59:12] [ info] [output:stdout:stdout.0] worker #0 started
[0] cpu.0: [[1689983952.736628018, {}], {"cpu_p"=>39.000000, "user_p"=>39.000000, "system_p"=>0.000000, "cpu0.p_cpu"=>39.000000, "cpu0.p_user"=>39.000000, "cpu0.p_system"=>0.000000}]
^C[2023/07/22 08:59:14] [engine] caught signal (SIGINT)
[0] cpu.0: [[1689983953.760921247, {}], {"cpu_p"=>34.000000, "user_p"=>33.000000, "system_p"=>1.000000, "cpu0.p_cpu"=>34.000000, "cpu0.p_user"=>33.000000, "cpu0.p_system"=>1.000000}]
[2023/07/22 08:59:14] [ warn] [engine] service will shutdown in max 5 seconds
[2023/07/22 08:59:14] [ info] [input] pausing cpu.0
[2023/07/22 08:59:14] [ info] [engine] service has stopped (0 pending tasks)
[2023/07/22 08:59:14] [ info] [input] pausing cpu.0
[2023/07/22 08:59:14] [ info] [output:stdout:stdout.0] thread worker #0 stopping...
[2023/07/22 08:59:14] [ info] [output:stdout:stdout.0] thread worker #0 stopped
==35254== 
==35254== HEAP SUMMARY:
==35254==     in use at exit: 95 bytes in 5 blocks
==35254==   total heap usage: 1,577 allocs, 1,572 frees, 968,886 bytes allocated
==35254== 
(snip)
==35254== 16 bytes in 1 blocks are still reachable in loss record 2 of 5
==35254==    at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==35254==    by 0x18E8B3: flb_calloc (flb_mem.h:95)
==35254==    by 0x191B7F: flb_main (fluent-bit.c:1210)
==35254==    by 0x192012: main (fluent-bit.c:1375)
==35254== 
==35254== 20 bytes in 1 blocks are possibly lost in loss record 3 of 5
==35254==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==35254==    by 0x1B76B0: flb_malloc (flb_mem.h:80)
==35254==    by 0x1B7893: sds_alloc (flb_sds.c:41)
==35254==    by 0x1B791A: flb_sds_create_len (flb_sds.c:62)
==35254==    by 0x1A31F4: flb_kv_item_create_len (flb_kv.c:42)
==35254==    by 0x190E65: set_trace_property (fluent-bit.c:815)
==35254==    by 0x191BA5: flb_main (fluent-bit.c:1213)
==35254==    by 0x192012: main (fluent-bit.c:1375)
==35254== 
==35254== 20 bytes in 1 blocks are possibly lost in loss record 4 of 5
==35254==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==35254==    by 0x1B76B0: flb_malloc (flb_mem.h:80)
==35254==    by 0x1B7893: sds_alloc (flb_sds.c:41)
==35254==    by 0x1B791A: flb_sds_create_len (flb_sds.c:62)
==35254==    by 0x1A3235: flb_kv_item_create_len (flb_kv.c:49)
==35254==    by 0x190E65: set_trace_property (fluent-bit.c:815)
==35254==    by 0x191BA5: flb_main (fluent-bit.c:1213)
==35254==    by 0x192012: main (fluent-bit.c:1375)
==35254== 
==35254== 32 bytes in 1 blocks are possibly lost in loss record 5 of 5
==35254==    at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==35254==    by 0x1A3143: flb_calloc (flb_mem.h:95)
==35254==    by 0x1A31AE: flb_kv_item_create_len (flb_kv.c:36)
==35254==    by 0x190E65: set_trace_property (fluent-bit.c:815)
==35254==    by 0x191BA5: flb_main (fluent-bit.c:1213)
==35254==    by 0x192012: main (fluent-bit.c:1375)
==35254== 
==35254== LEAK SUMMARY:
==35254==    definitely lost: 0 bytes in 0 blocks
==35254==    indirectly lost: 0 bytes in 0 blocks
==35254==      possibly lost: 72 bytes in 3 blocks
==35254==    still reachable: 23 bytes in 2 blocks
==35254==         suppressed: 0 bytes in 0 blocks
==35254== 
==35254== For lists of detected and suppressed errors, rerun with: -s
==35254== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)

@nokute78 nokute78 temporarily deployed to pr July 22, 2023 00:29 — with GitHub Actions Inactive
@edsiper edsiper added this to the Fluent Bit v2.1.8 milestone Jul 24, 2023
@edsiper edsiper merged commit 1d83649 into fluent:master Jul 25, 2023
@nokute78 nokute78 deleted the cleanup_signal_handler branch July 28, 2023 21:39
Wiston999 pushed a commit to Wiston999/fluent-bit that referenced this pull request Aug 7, 2023
- remove cleanup code from flb_signal_exit
- release trace_props

Signed-off-by: Takahiro Yamashita <[email protected]>
leonardo-albertovich pushed a commit that referenced this pull request Oct 5, 2023
- remove cleanup code from flb_signal_exit
- release trace_props

Signed-off-by: Takahiro Yamashita <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants