diff options
| author | Kirill Petrashin <kirill8201@yandex.ru> | 2026-03-26 13:42:59 +0300 |
|---|---|---|
| committer | Kirill Petrashin <kirill8201@yandex.ru> | 2026-03-26 13:42:59 +0300 |
| commit | 0a6f8b49723aa8da143953bc011582542d2f2010 (patch) | |
| tree | d2fb6216ff0815a8539d3b315e188181e98bbf89 /priority_queue.c | |
| parent | 5bf01bf1955cb1be6dc498543f8b2064b3424177 (diff) | |
| download | astar-0a6f8b49723aa8da143953bc011582542d2f2010.tar.xz | |
Fix memory leaks
Diffstat (limited to 'priority_queue.c')
| -rw-r--r-- | priority_queue.c | 13 |
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); +} |
