fix a memory leak caused by faulty _unref calls