I have the following code:
char *get_string_property_2(IOHIDDeviceRef device, CFStringRef prop)
{
CFStringRef str = IOHIDDeviceGetProperty(device, prop);
if(str)
{
CFIndex str_len = CFStringGetLength(str);
...
}
...
}
sometimes (not always) I get a crash in CFStringGetLengthwith the following log:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00007fff770083a8
Thread 8 Crashed:
0 libobjc.A.dylib 0x00007fff88e22097 objc_msgSend + 23
1 libtobii_usb.dylib 0x00000001081c4f72 get_string_property_2 + 130 (macosx.c:99)
2 serviced 0x00000001081a5fad device_removed_callback + 285 (daemond_mac.c:614)
3 libsystem_pthread.dylib 0x00007fff8ae35899 _pthread_body + 138
4 libsystem_pthread.dylib 0x00007fff8ae3572a _pthread_start + 137
5 libsystem_pthread.dylib 0x00007fff8ae39fc9 thread_start + 13
How can i fix this? I check if str is NULL or not before the call CFStringGetLength, apparently this is not enough.
EDIT:
I still get this crash, always in the same place.
If this is a bad pointer, why doesn't one line break above in IOHIDDeviceGetProperty??
Is there any other way that I can get the length CFStringRef?
I suspect there is an error in the api.
user1851615
source
share