Close filedescriptors after using

Change-Id: I9d6833159e15d01d3616645e7f64661e9a1cd542