close i2c device file if read or write fails

The i2c device file typically '/dev/i2c-1' needs to be closed if reading or
writing fails. Otherwise the device file remains locked with exclusive
lock 'LOCK_EX'.