make sure we close and free appropriately, also close if there is an error on set
Merge branch 'free-close-race'