ipc/msg: fix race around refcount