http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56370
Bug #: 56370 Summary: RFE: warn on 'foo = realloc(foo, …)' Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: dw...@infradead.org I thought I actually knew C, but it's just been pointed out to me that I have a habit of doing 'foo = realloc(foo, …)', which causes a memory leak in the failure case because whatever 'foo' used to point to can never be freed. Looking around, I see the same bug is fairly common. It's very rarely sane to assign the return value of realloc() directly to the same variable which was its first argument. Only when you don't *care* about a memory leak, or where you have another copy of the pointer that used to be in 'foo' and can still free it. It would be nice if the compiler would warn about this idiom.