Prevent memory leak during search indexing.

See #457.