clausecker / nfc

Go bindings for the libnfc
https://pkg.go.dev/github.com/clausecker/nfc/v2
GNU Lesser General Public License v3.0
101 stars 20 forks source link

pass the handle to nfc_close before making it nil #7

Closed harikb closed 9 years ago

harikb commented 9 years ago

The following is a one line change to nfc/device.go . Earlier code was not closing the NFC reader. In my case, it was clearly visible with an led on SCL3711 staying lit after device.Close(). This one line swap fixed it. Please note that this is to the 2.0 branch. I could not compile the dev branch, probably because of version difference with libnfs. Since 2.0 is your stable branch, I made it for 2.0. Please make the same change to dev branch as well.

 diff --git a/2.0/nfc/device.go b/2.0/nfc/device.go
 index 3bf6a09..c8fe55b 100644
 --- a/2.0/nfc/device.go
 +++ b/2.0/nfc/device.go
 @@ -92,8 +92,8 @@ func (d Device) Close() error {
                 return nil
         }

 -       *d.d = nil
         C.nfc_close(*d.d)
+       *d.d = nil

         return nil
  }
clausecker commented 9 years ago

You are right, that's a bug. I'm currently without a proper development setup, you can expect this to be fixed by Monday.

clausecker commented 9 years ago

Fixed in revision 2c1f6662768542025ba317c09da16dfd3e7f6c06.