Introducing: __attribute__((__cleanup__))

I don't wanna hear about MSVC... or C++...
This fixes NUMEROUS memory leaks introduced by G_ReadDemoHeader,
which I was utterly oblivious to up until an hour ago
This commit is contained in:
GenericHeroGuy authored and Alug committed 2025-09-23 23:57:54 +02:00
1 parent af1507b530
commit 2b1b4544f9
2 files changed
+12

No files matched your search

+6
View File
@@ -567,6 +567,12 @@ UINT32 quickncasehash (const char *p, size_t n)
#endif
#endif
// the GNU cleanup attribute: plugging memory leaks since 2003!
// on scope exit, the cleanup function is called with a pointer to the declared variable,
// essentially behaving like a C++ destructor
// NOTE: you WILL have nasal troubles if the variable is not initialized
#define CLEANUP(f) __attribute__((__cleanup__(f)))
// An assert-type mechanism.
#ifdef PARANOIA
#define I_Assert(e) ((e) ? (void)0 : I_Error("assert failed: %s, file %s, line %d", #e, __FILE__, __LINE__))
+6
View File
@@ -171,6 +171,12 @@ void *Z_LevelPoolMalloc(size_t size);
void *Z_LevelPoolCalloc(size_t size);
void Z_LevelPoolFree(void *p, size_t size);
// for use with CLEANUP macro
FUNCINLINE static ATTRINLINE void Z_Pfree(void *p)
{
Z_Free(*(void **)p);
}
#ifdef __cplusplus
} // extern "C"
#endif