• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
CFDictionary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: CFDictionary
      • From: mmalcolm crawford <email@hidden>
  • Prev by Date: Re: Databasing and Cocoa
  • Next by Date: Resource fork question
  • Previous by thread: Re: NSButton darkens background when pressed
  • Next by thread: Re: CFDictionary
  • Index(es):
    • Date
    • Thread