Fix crash on save of configuration when output file is invalid.

Bugfix imported from 7x branch #5246