always close file handles in gpio_*

I was running out of file handles causing -1 being returned by all gpio_* functions, and tracked it down to these file handles not being closed in some cases in read and write.