aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-30 16:43:22 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-30 16:43:22 +0100
commit504d231429e2a5d2b31a876645b590bb4a6a03f6 (patch)
tree415c7d89cfcc8cdb5802a9ae0bdbd1bb71ca823c /backend
parent71380426426dffe787d1704a8fd639c4b1bbfad3 (diff)
WIP battle the memory leaks
Diffstat (limited to 'backend')
-rw-r--r--backend/Dungeon.cpp11
-rw-r--r--backend/Dungeon.h4
-rw-r--r--backend/Location.cpp4
-rw-r--r--backend/util.h5
-rw-r--r--backend/util.hpp11
5 files changed, 35 insertions, 0 deletions
diff --git a/backend/Dungeon.cpp b/backend/Dungeon.cpp
index 3de2f11..66a1fa3 100644
--- a/backend/Dungeon.cpp
+++ b/backend/Dungeon.cpp
@@ -1,5 +1,16 @@
+#include "Location.h"
#include "Dungeon.h"
#include "RNG.h"
+#include "util.h"
+
+
+Dungeon::Dungeon() {
+
+}
+
+Dungeon::~Dungeon() {
+ safe_free(this->locations);
+}
void Dungeon::update() {
diff --git a/backend/Dungeon.h b/backend/Dungeon.h
index 5740eb6..eaca6c3 100644
--- a/backend/Dungeon.h
+++ b/backend/Dungeon.h
@@ -6,6 +6,10 @@ class Location;
class Dungeon {
public:
+ Dungeon();
+ ~Dungeon();
+
+public:
void update();
void add_location(Location *);
Location * get_start_location();
diff --git a/backend/Location.cpp b/backend/Location.cpp
index 9add524..31df1e3 100644
--- a/backend/Location.cpp
+++ b/backend/Location.cpp
@@ -2,6 +2,8 @@
#include "Location.h"
#include "ListIterator.h"
+#include "Enemy.h"
+#include "Object.h"
#include "util.h"
Location::Location(const char * name, const char * description) {
@@ -12,6 +14,8 @@ Location::Location(const char * name, const char * description) {
Location::~Location() {
safe_free(this->name);
safe_free(this->description);
+ safe_free(this->enemies);
+ safe_free(this->objects);
}
void Location::set_name(const char * name) {
diff --git a/backend/util.h b/backend/util.h
index 1889698..44d9a49 100644
--- a/backend/util.h
+++ b/backend/util.h
@@ -1,6 +1,11 @@
#pragma once
+#include "List.h"
+
void safe_free(void * & ptr);
void safe_free(const char * & ptr);
+template <typename T>
+void safe_free(List<T *> & ptr_list);
+#include "util.hpp"
diff --git a/backend/util.hpp b/backend/util.hpp
new file mode 100644
index 0000000..2d9e76a
--- /dev/null
+++ b/backend/util.hpp
@@ -0,0 +1,11 @@
+#pragma once
+
+#include "util.h"
+
+template <typename T>
+void safe_free(List<T *> & ptr_list) {
+ for (T * obj : ptr_list)
+ delete obj;
+ ptr_list.clear();
+}
+