aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-03-22 11:25:48 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-03-22 22:20:28 -0400
commit9c921f7cce985ec59420793b2f6388b980fcfe5d (patch)
treedf3dfc721c78b502f805fdc3cdd2e186fbb10a56
parent2d88d8779fb5cbc0e466d22a75ef5e3e6877065e (diff)
downloadstasis-9c921f7cce985ec59420793b2f6388b980fcfe5d.tar.gz
Add GENERIC_ARRAY_FREE macro to avoid code duplications when freeing character arrays
-rw-r--r--include/omc.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/include/omc.h b/include/omc.h
index e693834..cbc5950 100644
--- a/include/omc.h
+++ b/include/omc.h
@@ -41,6 +41,12 @@
#define guard_runtime_free(X) do { if (X) { runtime_free(X); X = NULL; } } while (0)
#define guard_strlist_free(X) do { if (X) { strlist_free(X); X = NULL; } } while (0)
#define guard_free(X) do { if (X) { free(X); X = NULL; } } while (0)
+#define GENERIC_ARRAY_FREE(ARR) do { \
+ for (size_t ARR_I = 0; ARR && ARR[ARR_I] != NULL; ARR_I++) { \
+ guard_free(ARR[ARR_I]); \
+ } \
+ guard_free(ARR); \
+} while (0)
#define COE_CHECK_ABORT(COND, MSG) {\
if (COND) { \