uludaggonul / snow-dots

Automatically exported from code.google.com/p/snow-dots
0 stars 0 forks source link

mexHID sometimes crashes during closeDevice or terminate #35

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
This seems to happen when I'm debugging and I keep opening the same device(s) 
without necessarily cleaning up mexHID in a normal flow.

The specific location is in the mexHIDCloseEntryDevice function.  Apparently 
I'm trying to close a dictionary entry for an info struct that doesn't exist.  
I must not be cleaning something up completely...

It seems not to be the case that one of the *fields* of the info struct is NULL 
or uninitialized because the bus error happens as soon as the struct is 
accessed, not when the field value is used.

Original issue reported on code.google.com by Benjamin.Heasly on 16 Aug 2010 at 10:59

Attachments:

GoogleCodeExporter commented 8 years ago
Looking at the code, I think the problem is that I'm removing CFDictionary 
items from the callback of a Dictionary iterator function.  And this is unsafe 
according to Apple's CF API.

I probably miseed this in the past because the device removal flow is clumsy.  
It can happen a device at a time, or all at once, and the dictionary removal 
step is two steps removed from the iterator callback.

Original comment by Benjamin.Heasly on 16 Aug 2010 at 11:19

GoogleCodeExporter commented 8 years ago
So, there are three things that need to happen to each device, in either case:

 - close the device with the HID API
 - release the device info stored in the mexHID struct
 - remove the dictionary entry that contains the mexHID struct

But in the case of mexHIDTerminate, there's no point in removing all the 
dictionary entries, since the dictionary itself is about to be destroyed.

So I need to back the dictionary removal out to only happen when the user calls 
for mexHIDCloseDevice.  And the iterator should not call mexHIDCloseDevice.

Original comment by Benjamin.Heasly on 16 Aug 2010 at 11:26

GoogleCodeExporter commented 8 years ago
I think I have fixed this.

I didn't "back out" the dictionary removal because I had made parallel 
implementations for openDevice/closeDevice, and retainDevice/releaseDevices.

So instead the dictionary iterator callback does the HID API close and the 
mexHID info struct release on its own, and does not modify the dictionary 
itself.

Original comment by Benjamin.Heasly on 16 Aug 2010 at 11:47