[MacOS X][Carbon] Exception avec le framework AddressBook
Bonjour à tous,
J'utilise le framework AddressBook/Carbon sous MacOS X 10.5 pour accèder aux enregistrements du carnet d'adresses dans l'application que je développe actuellement. Toutefois, je suis confronté à problème que je n'arrive pas à résoudre : lors de l'appel d'une de mes fonctions, mon appli plante complétement.
En la débuggant sous eclipse, j'ai réussi à obtenir une stacktrace du problème :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
Thread [0] (Suspended: Signal 'EXC_BAD_ACCESS' received. Description: Could not access memory.)
16 objc_msgSend() 0x902a168c
15 CFRetain() 0x959cf286
14 CFDictionaryAddValue() 0x9599ee12
13 CFDictionaryCreateMutableCopy() 0x9599f2fa
12 -[NSCFDictionary mutableCopyWithZone:]() 0x92fe7171
11 -[NSObject mutableCopy]() 0x95a4e0aa
10 +[ABCDRecord propertyTypesForClass:withAddressBook:acquireLock:]() 0x927d62c1
9 -[ABAddressBook nts_PropertyTypesForRecordOfClass:]() 0x927d619b
8 -[ABAddressBook nts_TypeOfProperty:forTable:]() 0x927d611c
7 -[ABAddressBook typeOfProperty:forTable:]() 0x927d6088
6 -[ABSearchElementMatch initWithProperty:label:key:value:searchPeople:searchSubscribed:comparison:]() 0x927d5fcf
5 -[ABSearchElementMatch initWithProperty:label:key:value:searchPeople:comparison:]() 0x927d5e53
4 +[ABPerson searchElementForProperty:label:key:value:comparison:]() 0x927d5a48
3 ABPersonCreateSearchElement() 0x9282f5b1
2 getContactFromMail() /Users/masiwa/Documents/workspace/AddressBook/AddressBook.c:249 0x0000648c
1 main() /Users/masiwa/Documents/workspace/libTest/main.c:22 0x00001e1a |
J'ai ai donc déduit que cela venait de mon code suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
Personne* getContactFromMail(const char* email) {
Personne* pers = (Personne*) malloc(sizeof pers);
CFStringRef text;
if (email != NULL && strcmp(email, "") != 0) {
int index = 0;
ABAddressBookRef ab = ABGetSharedAddressBook();
ABSearchElementRef find = ABPersonCreateSearchElement(kABEmailProperty, NULL, NULL, CFStringCreateWithCString(kCFAllocatorDefault, email, CFStringGetSystemEncoding()), kABEqualCaseInsensitive);
if (find != NULL && ab != NULL) {
CFArrayRef array = ABCopyArrayOfMatchingRecords(ab, find);
CFRelease(find);
CFIndex count = CFArrayGetCount(array);
if (count > 0) {
ABRecordRef firstRecord = (ABRecordRef) CFArrayGetValueAtIndex(array,0);
... |
et plus spécialement de la ligne
Code:
ABSearchElementRef find = ABPersonCreateSearchElement(kABEmailProperty, NULL, NULL, CFStringCreateWithCString(kCFAllocatorDefault, email, CFStringGetSystemEncoding()), kABEqualCaseInsensitive);
mais j'ai beau chercher, je ne voit absolument pas ce qui peut poser problème dans ce bout de code... ni même la nature de l'exception générée (cf. la stacktrace...)
Si quelqu'un pouvait m'apporter quelques éclaicissements, je lui en serait fort gré ;)
Merci d'avance !