Fix a couple of leaks

As reported by coverity (and the pack one also by @arrbee), let's clean up pack and tree.

The tree changes are pretty trivial, just a couple of free calls.

Pack has changed the 'put' function, which now asserts that we're not trying to free a pack which we have not previously inserted into the map, as that means there's internal state corruption, so it would be unwise to continue.