From efa1e89facb31cc36e8cc73bb46123038e47e7fb Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 6 Mar 2024 23:41:21 +0900 Subject: [PATCH] utils: Remove a needless flb_free out_size is just for used to return the lentgth of ID string. Removing this flb_free does not cause memory leaks. ``` % leaks -atExit -- bin/flb-it-utils test_flb_utils_get_machine_id flb-it-utils(34841) MallocStackLogging: could not tag MSL-related memory as no_footprint, so those pages will be included in process footprint - (null) flb-it-utils(34841) MallocStackLogging: recording malloc and VM allocation stacks using lite mode Test test_flb_utils_get_machine_id... [ OK ] SUCCESS: All unit tests have passed. Process 34841 is not debuggable. Due to security restrictions, leaks can only show or save contents of readonly memory of restricted processes. Process: flb-it-utils [34841] Path: /Users/USER/*/flb-it-utils Load Address: 0x1023cc000 Identifier: flb-it-utils Version: 0 Code Type: ARM64 Platform: macOS Parent Process: leaks [34840] Date/Time: 2024-03-06 23:42:29.641 +0900 Launch Time: 2024-03-06 23:42:29.596 +0900 OS Version: macOS 14.3.1 (23D60) Report Version: 7 Analysis Tool: /usr/bin/leaks Physical footprint: 4385K Physical footprint (peak): 4385K Idle exit: untracked ---- leaks Report Version: 4.0, multi-line stacks Process 34841: 516 nodes malloced for 42 KB Process 34841: 0 leaks for 0 total leaked bytes. ``` Signed-off-by: Hiroshi Hatake --- src/flb_utils.c | 1 - tests/internal/utils.c | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/flb_utils.c b/src/flb_utils.c index b227af376c1..87637f1331d 100644 --- a/src/flb_utils.c +++ b/src/flb_utils.c @@ -1456,7 +1456,6 @@ int flb_utils_get_machine_id(char **out_id, size_t *out_size) CFRelease(serialNumber); if (bret == false) { - flb_free(*out_size); *out_size = 0; return -1; } diff --git a/tests/internal/utils.c b/tests/internal/utils.c index 119094bdeb7..beec9099ecc 100644 --- a/tests/internal/utils.c +++ b/tests/internal/utils.c @@ -605,6 +605,19 @@ void test_flb_utils_split_quoted_errors() TEST_CHECK(split == NULL); } +void test_flb_utils_get_machine_id() +{ + int ret; + char *id = NULL; + size_t size; + + ret = flb_utils_get_machine_id(&id, &size); + TEST_CHECK(size != 0); + TEST_CHECK(id != NULL); + + flb_free(id); +} + TEST_LIST = { /* JSON maps iteration */ { "url_split", test_url_split }, @@ -618,5 +631,6 @@ TEST_LIST = { { "test_flb_utils_split", test_flb_utils_split }, { "test_flb_utils_split_quoted", test_flb_utils_split_quoted}, { "test_flb_utils_split_quoted_errors", test_flb_utils_split_quoted_errors}, + { "test_flb_utils_get_machine_id", test_flb_utils_get_machine_id }, { 0 } };