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