From 1337d6e1fa1644974c734cf738575c6a9755c5ef Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Tue, 6 Jun 2023 00:21:09 +0200 Subject: Fixed some use-after-frees --- src/lib/pqueue.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/lib/pqueue.c') 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; -- cgit v1.2.3