https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127226
Bug ID: 127226
Summary: attribute for marking fields of pointer type that need
to be NULL at deallocation
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: uecker at gcc dot gnu.org
Target Milestone: ---
I would fine an attribute very useful that enables a warning and/or run-time
check when a pointer field is not NULL at the time the parent struct is
deallocated, either because it goes out of scope or because a pointer is passed
to a deallocation function.
struct child;
struct foo {
[[gnu::clean]] struct child *p;
};
void bar()
{
struct foo x = { malloc(sizeof(int); };
...
// child_dellocate(&x.p); would set x.p to NULL
} // warning if deallocation is missing
This is useful when there are complex data structures with many such children,
and one wants to make sure all are properly deallocated.