Close streams to avoid leakage

Close stream to avoid fd leakage