Fix memory leak caused by undisposed memorystream.