TS-1475: Fix memory leak in error case. Coverity #1022137