Correctly deallocate buffer