On 14/12/2018 06:09, Josh Freeman wrote:
    These three lines in createNewTask: cause the issue:

         NSString *string = [[NSString alloc] init];
         string = [textField stringValue];
     ...
    [string release];// With this, I've got an "exec_BAD_ACCESS" error when calling three times in a row createNewTask with the same string in textField


   The first line sets 'string' to a retained, empty string object. The next line sets 'string' to the object returned by [textField stringValue], leaking the previous string object (its address was forgotten while it was still retained). 'String' then points to an object that wasn't retained by your code, so sending it a release message will cause it to deallocate while it's still referenced elsewhere (segfaulting if it's accessed after that).

   You can fix the issue by removing the first & third lines (empty-string allocation, release call), and moving the 'string' var definition to the second line:

Note: you can also fix the issue by removing all references to retain / release and compiling with -fobjc-arc. There is absolutely no reason for not doing this in new Objective-C code. It will work with macOS, iOS, watchOS, tvOS, and GNUstep, and the compiler will generate code that is faster, smaller, and more likely to be correct than if you do this by hand.

David

_______________________________________________
Discuss-gnustep mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/discuss-gnustep

Reply via email to