You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The cleanup attribute does not seem to be supported. I get many many false positives for resource and mem leaks due to this.
cleanup (cleanup_function)
The cleanup attribute runs a function when the variable goes out of scope. This attribute can only be applied to auto function scope variables; it may not be applied to parameters or variables with static storage duration. The function must take one parameter, a pointer to a type compatible with the variable. The return value of the function (if any) is ignored.
If -fexceptions is enabled, then cleanup_function is run during the stack unwinding that happens during the processing of the exception. Note that the cleanup attribute does not allow the exception to be caught, only to perform an action. It is undefined what happens if cleanup_function does not return normally. https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
The text was updated successfully, but these errors were encountered:
Hi,
Thanks for reporting this. We haven't looked into the cleanup attribute yet, but would be happy to support it. Could you please give us some small example of how this attribute is used and what kind of false positive leaks you get?
Thanks,
Dulma
Hi,
Here is an example of how to use it. When a variable with the attribute goes out of scope the function specified with the cleanup attribute will be called. The typical usecase is for free'ing the variable. This saves us from manually freeing in all error cases etc.
#include <stdlib.h>
#include <string.h>
void my_cleanup_func(char **c)
{
puts("debug: cleanup_func called");
free(*c);
}
int main(int argc, char **argv)
{
__attribute__ ((cleanup(my_cleanup_func))) char *s = NULL;
s = strdup("demo string");
return 0; /* s goes out of scope. Cleanup function called - no leak */
}
The cleanup attribute does not seem to be supported. I get many many false positives for resource and mem leaks due to this.
The text was updated successfully, but these errors were encountered: