CFDictionary
CFDictionary
- Subject: CFDictionary
- From: Devon E Bowen <email@hidden>
- Date: Tue, 2 Mar 2004 12:24:11 -0500 (EST)
I'm having a memory management problem with CFDictionary. I am using
the System Configuration Framework to disable proxy settings. I've
attached the appropriate code segments.
Everything works fine if I don't release any memory that's given to me.
But when I try to do the right thing, it seg faults. I've narrowed the
problem down to the place where I copy the old proxy info. Freeing the
original dictionary causes strangeness when the copy is used later.
If I leak the original, though, it works fine.
The CFDictionaryCreateMutableCopy function is supposed to retain all
the values when it copies them. So I don't really understand the
reason for the problem. Does this have anything to do with callback
functions? Any tips? I should also note that I am new to programming
with the CF libs.
Devon
----------------------
// open connection and lock the database
session = SCPreferencesCreate(nil, CFSTR("ProgName"), nil);
SCPreferencesLock(session, TRUE);
// get the dictionary of data associated with proxy for net device 0
path = CFStringCreateWithCString(NULL, "/NetworkServices/0/Proxies",
kCFStringEncodingASCII);
CFDictionaryRef aProxy = SCPreferencesPathGetValue(session, paths);
// make a copy of the proxy data so we can modify it
dict = CFDictionaryCreateMutableCopy(NULL, 0, aProxy);
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// COMMENTING THE FOLLOWING LINE MAKES THE CODE WORK FINE
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
CFRelease(aProxy);
// set the HTTPEnabled variable to false - disabling the proxy setting
int intValue = 0;
CFNumberRef enabled = CFNumberCreate(NULL, kCFNumberIntType, &intValue);
CFDictionarySetValue(dict, CFSTR("HTTPEnable"), enabled);
CFRelease(enabled);
// vvvvvvvvvvvvvvvvvvvv
// set the new proxy dictionary as the real one - THIS IS WHAT CRASHES
// ^^^^^^^^^^^^^^^^^^^^
SCPreferencesPathSetValue(session, path, dict);
// clean up
CFRelease(dict);
CFRelease(path);
// commit changes and unlock
SCPreferencesCommitChanges(session);
SCPreferencesApplyChanges(session);
SCPreferencesUnlock(session);
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.