Some defensive programming at destruction time, and fix a latent dangling pointer bug.
Merge branch '1.4.x'