I have a custom free function "custom_free" that deallocates memory allocated by malloc or by a custom alloc function "custom_alloc".
When i run cppcheck, it reports "mismatchAllocDealloc" whenever it finds something like this
Is there a way to define in the ".cfg" to indicate free and custom_free are equivalent ?
I tried this
<memory>
<alloc>malloc</alloc>
<dealloc>free</dealloc>
<dealloc>custom_free</dealloc>
</memory>
This works , but then it applies this rule for all paramters to custom_free whereas i want the rule to be applied only for the 3rd parameter. Thats because rest of the parameters are not deallocated by this custom_free function.
Slightly related thread: https://sourceforge.net/p/cppcheck/discussion/general/thread/d9737d5d/
While it seems possible to specify arg options for alloc and dealloc, Cppcheck does not seem to take these into account.
@danmar Should we create a special ticket for such issues, requesting arg options to work? I have not found any ticket that already handles it directly.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a custom free function "custom_free" that deallocates memory allocated by malloc or by a custom alloc function "custom_alloc".
When i run cppcheck, it reports "mismatchAllocDealloc" whenever it finds something like this
str = malloc(100);
custom_free(str); / Valid - custom_free internally calls free . Still cppcheck generates mismatchAllocDealloc /
Is there a way to define in the ".cfg" to indicate free and custom_free are equivalent ?
I tried this
<memory>
<alloc>malloc</alloc>
<dealloc>free</dealloc>
<dealloc>custom_free</dealloc>
</memory>
This works , but then it applies this rule for all paramters to custom_free whereas i want the rule to be applied only for the 3rd parameter. Thats because rest of the parameters are not deallocated by this custom_free function.
So tried this -
<memory>
<alloc>malloc</alloc>
<dealloc>free</dealloc>
<dealloc arg="3">custom_free</dealloc>
</memory>
But this doesn't work and it generates mismatchAllocDealloc.
Please note, I do not want to suppress mismatchAllocDealloc considering it may suppress genuine issues.
Thanks
Siddharth
Last edit: Siddharth 2019-01-08
Slightly related thread: https://sourceforge.net/p/cppcheck/discussion/general/thread/d9737d5d/
While it seems possible to specify
arg
options foralloc
anddealloc
, Cppcheck does not seem to take these into account.@danmar Should we create a special ticket for such issues, requesting
arg
options to work? I have not found any ticket that already handles it directly.sounds ok to me.