proto-shell: fix potential use-after-free