I extended the code we wrote today to include the freeing functionality discussed at the very end. The new library code for apply_fn and pq_free is at the bottom of heaps-extended.c. There are also updated signatures in heaps-extended.h.
If you have any comments or see any errors, please let me know.