Some defensive programming at destruction time, and fix a latent dangling pointer bug.