CTest: fix crash if source file for coverage cannot be found
The opened XML elements were not closed, so an assert was triggered when the file was finally closed. If CMake is built with assertions disabled then an invalid XML file will be produced.
A testcase can be found in #17293.