TS-1475: Coverity 1214713 - close fp
TS-1475: Coverity 1215253 Out-of-bounds write
TS-1475: Coverity 120023 120024 - fix resource leak
TS-1475: Coverity 120022 - fix resource leak
TS-1475: Coverity 1021842 - fix resource leak
TS-1475: Coverity 1021843 - fix resource leak
TS-1475: Coverity 120019- fix resource leak
TS-1475: Coverity 120020 - fix resource leak
TS-1475: Coverity 120021 - fix resource leak
TS-1475: Coverity 1021862 - fix resource leak