objective c - DiskRef disappears while enumerating disks in callback method -


i have used diskarbitration classes project disk-arbitrator on github in project i'm working on.

i mounting/unmounting os x installer disk images via hdiutil , callback method defined daregisterdiskdescriptionchangedcallback crashes disk list mutated while enumerating, , diskref get's passed becomes null.

here function get's called callback:

daregisterdiskdescriptionchangedcallback(session, matching, null, diskdescriptionchangedcallback, (__bridge void *)([nbcdisk class]));  ...  void diskdescriptionchangedcallback(dadiskref diskref, cfarrayref keys, void *context) { #pragma unused(keys)     if (context != (__bridge void *)([nbcdisk class])) return;      nsset *uniquediskscopy = [uniquedisks copy];     ( nbcdisk *disk in uniquediskscopy ) {         if ( cfhash(diskref) == [disk hash] ) {             cfdictionaryref desc = dadiskcopydescription(diskref);             disk.diskdescription = desc;             cfrelease(desc);              [[nsnotificationcenter defaultcenter] postnotificationname:dadiskdidchangenotification object:disk];         }     } } 

i solved problem being mutated while enumerating making copy , enumerate on that.

but, code crash with: "*** cfhash() called null ***"

and because disk has disappeared , diskref has been deallocated.

so, need tips here. wanted try , make copy of diskref, , tried doing this:

dadiskref diskrefcopy = diskref; 

but did not work either. there way make copy? or there way altogether should approach this.

so, need tips here. wanted try , make copy of diskref, , tried doing this:

dadiskref diskrefcopy = diskref;

since you're interacting core foundation; use -

cfretain(diskref); 

also, have @ following reference in disk-arbitrator project, file disk.m @ line #80:

disk = cfretain(diskref);

and line #75:

return [uniquedisk retain];

i hope helps! btw taking copy not needed nsset *uniquediskscopy = [uniquedisks copy];.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -