TS-1475: Coverity 1226155 - fix resource leak
TS-1475: Coverity 1226154 - fix resource leak
TS-1475: Coverity 1021651 - fix double free.
TS-1475: Coverity 1021652 - fix double free.
TS-1475: Coverity 1021652 - fix double free.
TS-1475: Coverity 1196450 Out-of-bounds access - suppressed warning