https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106854
Bug ID: 106854 Summary: [[gnu::malloc(deallocator)]] for non-pointer functions (e.g., fd) Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: colomar.6.4.3 at gmail dot com Target Milestone: --- Some stuff is allocated and deallocated through non-pointer types. Most of the time it's file descriptors, i.e., int. Since [[gnu::malloc(f)]] is independent of [[gnu::malloc]], it could be used for such cases: int close(int fd); [[gnu::malloc(close)]] int open(const char *pathname, int flags, ...); Notice that [[gnu::malloc]] can't be used above. [[gnu::malloc(f)]] has no reason to be restricted to functions returning pointers, has it? Could you allow using it for file descriptors? Otherwise, a more generic [[open(close)]] attribute might be reasonable. Currently, it results in a warning: $ cat fd.c && echo && cc -Wall -Wextra -S fd.c #include <fcntl.h> #include <unistd.h> [[gnu::malloc(close)]] int g(void) { return open("foo", O_RDONLY); } fd.c:6:1: warning: ‘malloc’ attribute ignored on functions returning ‘int’; valid only for pointer return types [-Wattributes] 6 | { | ^