Fix memory leak in error. Fixes #2025