TS-1475: Fix bug where local buffer might still be referenced. Coverity #1200047