The line
return (__bridge DCSDictionaryRef)d;
gives me a “Address of stack memory associated with local variable retured to caller?” warning. Ideally I think I ought to create a new copy of the DCSDictionaryRef instance but I’m absolute clueless about how it works.
Would appreciate any hints/help on how I can get rid of the warning (and a potential leak or the object being gcollected midway).
P.S. DCSCopyAvailableDictionaries and DCSDictionaryGetShortName are one of the ‘undocumented’ functions in CoreFoundation.
DCSDictionaryRef _DCSDictionary() {
NSArray *dicts = DCSCopyAvailableDictionaries();
for (NSObject *d in dicts) {
NSString *sn = DCSDictionaryGetShortName((__bridge DCSDictionaryRef)d);
NSLog(@"%@", sn);
if ([sn isEqualToString:@"Thesaurus"]) {
return (__bridge DCSDictionaryRef)d;
}
}
return NULL;
}
I believe you need one of the following:
copyfunctionHere’s Apple documentation about memory management for CoreFoundation. The gist is you need a
Copyfunction applicable to the data type you are using. See if you can locate and call a DCSDictionaryRef copy function. The example in the linked documentation is that a function calledCFStringCreateCopywould be used to copy a CFString object.I’ve never tried something like this before, but it might be possible to archive the object (assuming you are able to know its size), but this also entails knowing which bits represent pointers, and subsequently archiving the objects the pointers point to as well, which also entails knowing the types and sizes of those objects. If you’re able to successfully archive it, then you might have a shot at unarchiving it elsewhere in memory.
I think this is a very deep rabbit hole.