Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Coverity CID: 219722] Resource leak in tests/lib/mem_alloc/src/main.c #33318

Closed
zephyrbot opened this issue Mar 13, 2021 · 1 comment
Closed
Assignees
Labels
bug The issue is a bug, or the PR is fixing a bug Coverity A Coverity detected issue or its fix priority: low Low impact/importance bug

Comments

@zephyrbot
Copy link
Collaborator

Static code scan issues found in file:

https:/zephyrproject-rtos/zephyr/tree/b4f5b9e23770f2c9cddf95fef7b9af32da309f7f/tests/lib/mem_alloc/src/main.c#L233

Category: Resource leaks
Function: test_reallocarray
Component: Tests
CID: 219722

Details:

ptr = reloc_ptr;

227         (void)memset(ptr, 'p', orig_size);
228    
229         char *reloc_ptr = reallocarray(ptr, 2, orig_size);
230    
231         zassert_not_null(reloc_ptr, "reallocarray failed");
232         zassert_not_null((ptr), "malloc/reallocarray failed, errno: %d", errno);
>>>     CID 219722:  Resource leaks  (RESOURCE_LEAK)
>>>     Overwriting "ptr" in "ptr = reloc_ptr" leaks the storage that "ptr" points to.
233         ptr = reloc_ptr;
234    
235         (void)memset(filled_buf, 'p', BUF_LEN);
236         zassert_true(((memcmp(ptr, filled_buf, BUF_LEN)) == 0),
237                 "realloc failed to copy malloc data, errno: %d", errno);
238    

Please fix or provide comments in coverity using the link:

https://scan9.coverity.com/reports.htm#v29271/p12996

Note: This issue was created automatically. Priority was set based on classification
of the file affected and the impact field in coverity. Assignees were set using the CODEOWNERS file.

@zephyrbot zephyrbot added bug The issue is a bug, or the PR is fixing a bug Coverity A Coverity detected issue or its fix priority: low Low impact/importance bug labels Mar 13, 2021
@rljordan rljordan assigned chen-png and unassigned nashif Mar 17, 2021
@enjiamai enjiamai assigned enjiamai and unassigned chen-png Mar 17, 2021
@enjiamai
Copy link
Collaborator

enjiamai commented Mar 23, 2021

After analyzing it, this is likely to be a false positive. Because after calling the reallocarray(), the original memory chuck that "ptr" point to, is no need to be free. It might become a larger or smaller memory chunk. No memory would be leak here.

I think there is no need to fix it.

@rljordan rljordan assigned nashif and unassigned enjiamai Mar 24, 2021
@nashif nashif closed this as completed Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug Coverity A Coverity detected issue or its fix priority: low Low impact/importance bug
Projects
None yet
Development

No branches or pull requests

4 participants