fix memory duplication due to bytearrayoutputstream