[Freeciv-Dev] (PR#15126) patch: fc_free macro
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=15126 >
patch #3:
#define fc_free(ptr) fc_real_free((&ptr))
void fc_real_free(void **ptr)
{
free(*ptr);
*ptr = NULL;
}
I think this fits best to the fc_*alloc macros, even though it adds a
little bit overhead.
Index: utility/mem.c
===================================================================
--- utility/mem.c (Revision 11431)
+++ utility/mem.c (Arbeitskopie)
@@ -129,6 +129,15 @@
return ptr;
}
+/*******************************************************************************
+ Function used by fc_free macro, free() replacement
+*******************************************************************************/
+void fc_real_free(void **ptr)
+{
+ free(*ptr);
+ *ptr = NULL;
+}
+
/***************************************************************
Function used by mystrdup macro, strdup() replacement
No need to check return value.
Index: utility/mem.h
===================================================================
--- utility/mem.h (Revision 11431)
+++ utility/mem.h (Arbeitskopie)
@@ -29,6 +29,8 @@
__LINE__, __FILE__)
#define fc_calloc(n,esz) fc_real_calloc((n), (esz), "calloc", \
__LINE__, __FILE__)
+
+#define fc_free(ptr) fc_real_free((&ptr))
#define mystrdup(str) real_mystrdup((str), "strdup", \
__LINE__, __FILE__)
@@ -45,6 +47,8 @@
void *fc_real_calloc(size_t nelem, size_t elsize,
const char *called_as, int line, const char *file);
+void fc_real_free(void **ptr);
+
char *real_mystrdup(const char *str,
const char *called_as, int line, const char *file);
|
|