Hello.
Please, give me an advice.
We have just started using of cppcheck and we have some legacy code which uses non-trivial memory allocation functions (they are provided by a library), which initialize allocated memory by resources from file:
const char * Resource_GetString(const char * moduleName, word resourceID); // Allocates and initializes one string.
void Resource_Release(const char * moduleName, word resourceID); // Deallocates one string.
void Resource_ReleaseAll(const char * moduleName); // Deallocates all strings for specified program module.
We have added memory block to cfg file:
<memory>
<alloc init="true">Resource_GetString</alloc>
<dealloc>Resource_Release</dealloc>
</memory>
And we have a lot of "memory leak" error messages from cppcheck in code, which allocates many resources by Resource_GetString, and releases them all by only one Resource_ReleaseAll. And there is no real memory leak.
Is there a way to help cppcheck to understand this code (function Resource_ReleaseAll)?
Of course we can modify this code to use allocate-release pair, but we don't want to touch legacy code when it doesn't contain real errors.
Thank you for attention.
Last edit: Ilya Yunkin 2018-01-21
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello.
Please, give me an advice.
We have just started using of cppcheck and we have some legacy code which uses non-trivial memory allocation functions (they are provided by a library), which initialize allocated memory by resources from file:
We have added memory block to cfg file:
<memory>
<alloc init="true">Resource_GetString</alloc>
<dealloc>Resource_Release</dealloc>
</memory>
And we have a lot of "memory leak" error messages from cppcheck in code, which allocates many resources by Resource_GetString, and releases them all by only one Resource_ReleaseAll. And there is no real memory leak.
Is there a way to help cppcheck to understand this code (function Resource_ReleaseAll)?
Of course we can modify this code to use allocate-release pair, but we don't want to touch legacy code when it doesn't contain real errors.
Thank you for attention.
Last edit: Ilya Yunkin 2018-01-21
as far as I see, you can't configure this properly. I would suggest that you don't configure this in <memory>.