Tk Source Code

View Ticket
Login
Ticket UUID: fa4694dcd08fbf0f9150badfc50b66b8b7355c2b
Title: Aqua: fix TKNSString leak in TkpConfigureMenuEntry()
Type: Patch Version: 8.6.12
Submitter: chrstphrchvz Created on: 2023-07-10 13:18:17
Subsystem: 11. Aqua Menus Assigned To: fvogel
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2023-07-16 20:23:29
Resolution: Fixed Closed By: fvogel
    Closed on: 2023-07-16 20:23:29
Description:

NSString *title can possibly be assigned @"" or the return value of [NSString stringWithFormat:…] which is always autoreleased. So it made sense to also autorelease title after assigning it [[NSString alloc] initWithBytes:… length:… encoding:…], as done prior to [236cec5b46c1]. This still needs to be done to avoid leaking the result of [[TKNSString alloc] initWithTclUtfBytes:… length:…]; see attached patch.

User Comments: fvogel added on 2023-07-16 20:23:29:
Understood. Thank you for the link!

chrstphrchvz added on 2023-07-16 12:56:15:

Building Cocoa Applications 4.2.12 “autorelease and the NSAutoreleasePool Class” says [NSString stringWithFormat:…] is autoreleased, and equivalent to [[[NSString alloc] initWithFormat:…] autorelease]. Although Apple would rather recommend following more general rules: the important thing is whether you own the object (which can be inferred from the name of the method retuning the object), rather than e.g. whether something else could have already autoreleased the object; and to release an object only when you have ownership.


fvogel added on 2023-07-15 08:59:19:
OK thanks for the feedback, I have now merged Chirstopher's patch.

Leaving the ticket open for the moment, pending Christopher's answer to my question below.

marc_culler (claiming to be Marc Culler) added on 2023-07-14 21:56:22:
I think it was a mistake.  I thought it was unnecessary.

fvogel added on 2023-07-14 20:03:02:

Agreed.

@Christopher, just a question: I couldn't find (in Apple's documentation) the information you state "[NSString stringWithFormat:…] is always autoreleased", how do you know this please?

@Marc, was there any reason why you removed the autorelease message in your commit [236cec5b46c1] ?


Attachments: