objective c - Having hard time where to put CFRelease calls -


i'm having hard time put cfrelease() calls in below code. either if put cfrelease() inside 1 bracket complain missing in bracket.

abmutablemultivalueref phones = abrecordcopyvalue(person, kabpersonphoneproperty);  if (phones == nil || abmultivaluegetcount(phones) == 0) {      cfarrayref linkedcontacts = abpersoncopyarrayofalllinkedpeople(person);     phones = abmultivaluecreatemutable(kabpersonphoneproperty);      (int = 0; < cfarraygetcount(linkedcontacts); i++) {          abrecordref linkedcontact = cfarraygetvalueatindex(linkedcontacts, i);         abmultivalueref linkedphones = abrecordcopyvalue(linkedcontact, kabpersonphoneproperty);          if (linkedphones != nil && abmultivaluegetcount(linkedphones) > 0) {              (int j = 0; j < abmultivaluegetcount(linkedphones); j++) {                  abmultivalueaddvalueandlabel(phones, abmultivaluecopyvalueatindex(linkedphones, j), null, null);             }         }     }      if (abmultivaluegetcount(phones) == 0) {          return no;     } } 

as know, have release objects "own", i.e. objects returned function "create" or "copy" in name, but only if call succeeded. if functions returns null, must not call cfrelease on returned value.

for example, in code

abmultivalueref linkedphones = abrecordcopyvalue(linkedcontact, kabpersonphoneproperty); if (linkedphones != nil && abmultivaluegetcount(linkedphones) > 0) {     // ... } 

is unclear whether call cfrelease(linkedphones) @ end of if-block or not. might better check separately if call succeeded or not.

so part of code like:

abmultivalueref linkedphones = abrecordcopyvalue(linkedcontact, kabpersonphoneproperty); if (linkedphones != nil) {     (int j = 0; j < abmultivaluegetcount(linkedphones); j++) {         cftyperef value = abmultivaluecopyvalueatindex(linkedphones, j);         if (value != nil) {             abmultivalueaddvalueandlabel(phones, value, null, null);             cfrelease(value);         }     }     cfrelease(linkedphones); } 

i hope started rewrite complete function analyzer-safe!


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -