aboutsummaryrefslogtreecommitdiff
path: root/backend/util.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-01 19:40:24 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-01 19:40:24 +0100
commitbdf6ac149ec260dab767663419731b302679f458 (patch)
treeb22277e55cf4167e7bd4af92c21f174ee76686ae /backend/util.cpp
parent221b08e07246e84587b4144eca5564ce9ad3a20a (diff)
test for memory leaks
Diffstat (limited to 'backend/util.cpp')
-rw-r--r--backend/util.cpp27
1 files changed, 23 insertions, 4 deletions
diff --git a/backend/util.cpp b/backend/util.cpp
index afac06e..557df4c 100644
--- a/backend/util.cpp
+++ b/backend/util.cpp
@@ -1,22 +1,41 @@
+#include <stdio.h>
#include <stdlib.h>
#include "util.h"
+#include "WeaponObject.h"
+#include "ArmorObject.h"
+
+template <>
void safe_free(void * & ptr) {
if (ptr == nullptr) return;
free(ptr);
ptr = nullptr;
}
+
+template <>
void safe_free(const char * & ptr) {
auto x = static_cast<void *>(const_cast<char *>(ptr));
safe_free(x);
}
-void safe_free(char * & ptr) {
- auto x = static_cast<void *>(ptr);
- safe_free(x);
+
+template <>
+void safe_free(WeaponObject * & ptr) {
+ delete ptr;
}
-void safe_free(FILE * & ptr) {
+
+template <>
+void safe_free(ArmorObject * & ptr) {
+ delete ptr;
+}
+
+
+template <typename T>
+void safe_free(T * & ptr) {
auto x = static_cast<void *>(ptr);
safe_free(x);
}
+template void safe_free(char * &);
+template void safe_free(FILE * &);
+