Fix refcount leak, fix #618