Fix memory leak in previous commit.

Continued work for #9457.