Skip to content

Commit

Permalink
utils: Remove a needless flb_free
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cosmo0920 authored and edsiper committed Mar 12, 2024
1 parent 431b287 commit efa1e89
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/flb_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/internal/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 }
};

0 comments on commit efa1e89

Please sign in to comment.