It is safe too call free() with a NULL pointer. Minor other cleanup.

In particular, use a different bailout write up for pop_duplicate().