Fix two use-after-free bugs.