Fix bug and potentially a resource leak

The resource leak went away after I updated rust, so I'm
not entirely sure I fixed it.  I did ensure that all refs
were dropped before updating rust though.