bugGNUstep - Bugs: bug #18804, -[NSURLHandle resourceData] fails...

Group
 
 

bug #18804: -[NSURLHandle resourceData] fails to retain & autorelease its returned value

Submitter:  Larry Campbell <lcampbel>
Submitted:  Tue 16 Jan 2007 06:29:15 PM UTC
   
 
Category:  Base/Foundation Severity:  3 - Normal
Item Group:  Change Request Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 18 Jan 2007 08:49:44 PM UTC, comment #3: 

I would like to note that this class/method seems a likely candidate to be used in certain performance critical servers in potentially multithreaded environments.  The copy/autorelease approach could have a significant impact in the multithreaded case due to accessing the autorelease pool. I would favor avoiding returning an autoreleased objects in this case.

David Ayers <ayers>
Group Member
Wed 17 Jan 2007 01:44:26 PM UTC, comment #2: 

I stand corrected. I checked and found that MacOS X behaves the same way. I withdraw my suggestion.

Larry Campbell <lcampbel>
Wed 17 Jan 2007 08:37:56 AM UTC, comment #1: 

This is plainly not a bug (since it's legitimate/normal to return ivars whose life is that of the receiver, and the GNUstep and MacOS-X documentation don't say that the value will be autoreleased), so I have treated it as a change request instead.
I've implemented it for consistency.

This behavior is actually an undocumented implementation detail, and can't be guaranteed in GNUstep-base or Cocoa Foundation.
This means that if an application depends on this implementation detail then there is a bug in the application ... the general rule for handling objects returned by methods is that the caller MUST retain the object immediately before calling any other method which might possibly cause it to be destroyed.  Assuming that the object will persist as long as the enclosing autorelease pool persists is an error unless the method is specifically documented as returning an autoreleased object.

Richard Frith-Macdonald <CaS>
Group Member
Tue 16 Jan 2007 06:29:15 PM UTC, original submission:  

-[NSURLHandle resourceData] should always retain & autorelease its returned value; otherwise, releasing the handle will deallocate the data.

The fix: in NSURLHandle.m, at line 541 (wrt gnustep-base 1.13.0), change this:

      if (d != nil)
        {
          ASSIGNCOPY(_data, d);
        }
      return _data;


to this:

      if (d != nil)
        {
          ASSIGNCOPY(_data, d);
        }
      return AUTORELEASE([_data copy]);

Larry Campbell <lcampbel>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by ayers (Posted a comment)
  • -email is unavailable- added by CaS (Posted a comment)
  • -email is unavailable- added by lcampbel (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2007-01-17 CaS Item GroupBug Change Request
        StatusNone Fixed
        Open/ClosedOpen Closed
    2007-01-16 lcampbel Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code