For a C (gcc 8.5) project we utilize a AUTO FREE Macro that is getting hit by c:S3584 on sonarQube 10.3.0.82913. This memory is cleaned up when the pointer goes out of scope but every use of it is indicated by the last use of the variable.
The line immediately after the last usage of some_int_array comes back as a Potential leak of memory which I believe to be a false positive. I obviously donât want to ignore this rather important rule so looking for some suggestions/advice.
We are building using the build wrapper in a gitlab pipeline.
However If I make functions for each type eg: int** the error comes back. The problem with this solution is the compiler starts complaining about the type mismatch between the various types.
I tried to make type specific implementations but then sonarqube started detecting it as a memory leak again.
We need to think about this carefully and see whether we modify this rule to make it aware of __cleanup__ attributes, or if we add support for it on the engine. The former is easier, and the latter is more complete as it could catch accidental double frees as well, but it is more involved.
As for workarounds, I can not think of any option besides disabling the rule, unfortunately.
Thank you for confirming the issue and sharing the ticket. I donât find ignoring this rule acceptable cause it would cause too many missed issues in this legacy code so knowing this is something you guys might be able to add is great news.