fix dest memory leak when writing streams