Use reference counting in SafeHandleBase to ensure git_threads_shutdown() only gets called after the last handle is released (joint work with Sam Harwell)