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