aboutsummaryrefslogtreecommitdiff
path: root/priority_queue.c
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-03-26 13:42:59 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-03-26 13:42:59 +0300
commit0a6f8b49723aa8da143953bc011582542d2f2010 (patch)
treed2fb6216ff0815a8539d3b315e188181e98bbf89 /priority_queue.c
parent5bf01bf1955cb1be6dc498543f8b2064b3424177 (diff)
downloadastar-0a6f8b49723aa8da143953bc011582542d2f2010.tar.xz
Fix memory leaks
Diffstat (limited to 'priority_queue.c')
-rw-r--r--priority_queue.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/priority_queue.c b/priority_queue.c
index d2517a6..d4be6e2 100644
--- a/priority_queue.c
+++ b/priority_queue.c
@@ -24,6 +24,7 @@ int ppq_insert(PositionPQ **ppq, Position pos, size_t priority) {
}
PositionPQ *n = ppq_new(pos, priority);
+
if (start->priority > priority) {
n->next = start;
start = n;
@@ -34,11 +35,13 @@ int ppq_insert(PositionPQ **ppq, Position pos, size_t priority) {
while(temp->next != NULL && temp->next->priority <= priority) {
if (temp->pos.x == pos.x && temp->pos.y == pos.y && temp->priority <= priority) {
+ free(n);
return 3; /* pos is already in ppq with a fine priority */
}
temp = temp->next;
}
if (temp->pos.x == pos.x && temp->pos.y == pos.y && temp->priority <= priority) {
+ free(n);
return 3; /* pos is already in ppq with a fine priority */
}
@@ -82,3 +85,13 @@ void ppq_print(PositionPQ *ppq) {
}
printf("%i - %li: %li, %li\n", i++, ppq->priority, ppq->pos.x, ppq->pos.y);
}
+
+void ppq_free(PositionPQ *ppq) {
+ if (ppq == NULL) return;
+ while(ppq->next != NULL) {
+ PositionPQ *t = ppq;
+ ppq = ppq->next;
+ free(t);
+ }
+ if (ppq != NULL) free(ppq);
+}