Add missing calls to close()

We did not close the file correctly, so file descriptors were leaking.

Signed-off-by: David Hauweele <david@hauweele.net>