Merge pull request #367 from Dmitry-Me/preAssertsToEnsureNoBufferLeaks

Asserts to ensure old buffer is not leaked when allocating a new one