diff options
author | Marvin Borner | 2023-06-06 00:21:09 +0200 |
---|---|---|
committer | Marvin Borner | 2023-06-06 00:21:09 +0200 |
commit | 1337d6e1fa1644974c734cf738575c6a9755c5ef (patch) | |
tree | efed2e0f42168615d475f977187a0e5c7cf54b32 /src/lib | |
parent | c9b0537a1f04c8a28e1f9aa9a6112a1e59653eea (diff) |
Fixed some use-after-frees
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/pqueue.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lib/pqueue.c b/src/lib/pqueue.c index cf0611f..6162cbc 100644 --- a/src/lib/pqueue.c +++ b/src/lib/pqueue.c @@ -160,6 +160,18 @@ void pqueue_change_priority(struct pqueue *q, pqueue_pri_t new_pri, void *d) percolate_down(q, posn); } +int pqueue_remove(struct pqueue *q, void *d) +{ + size_t posn = q->getpos(d); + q->d[posn] = q->d[--q->size]; + if (q->cmppri(q->getpri(d), q->getpri(q->d[posn]))) + bubble_up(q, posn); + else + percolate_down(q, posn); + + return 0; +} + void *pqueue_pop(struct pqueue *q) { void *head; |