The short circuit in the remove function when the element is the last in the
heap, failed to add the removed slot back to the freelist.
Fixes #22644
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22646)
ASSERT_USED(pq, n);
- if (n == pq->htop - 1)
+ if (n == pq->htop - 1) {
+ pq->elements[elem].posn = pq->freelist;
+ pq->freelist = elem;
+#ifndef NDEBUG
+ pq->elements[elem].used = 0;
+#endif
return pq->heap[--pq->htop].data;
+ }
if (n > 0)
pqueue_force_bottom(pq, n);
return ossl_pqueue_pop(pq);