fix buf: free malloc buffer when close stream