executeAndReturnError of NSAppleScript leaks memory

Originator:m.hanauska
Number:rdar://29088854 Date Originated:03-Nov-2016
Status:Open Resolved:
Product:macOS + SDK Product Version:10.12.2
Classification:Serious Bug Reproducible:Always
 
Summary:
Basically, these two lines of code leak memory:

script = [[NSAppleScript alloc] initWithSource:scriptSrc];
returnEventDescriptor = [script executeAndReturnError:&errorDict];

See Instruments stack trace attached.

Steps to Reproduce:
1. Compile code above.
2. Run it.
3. Check for leaks.

Expected Results:
No leaks.

Actual Results:
Leaks.

Version:
10.11.6

Comments

Here as the answers:

> Do you retain returnEventDescriptor?

No, I don't retain it. And I also don't see how that would play a role as retaining it would not cause a leak as long as I also release it. Also it's not returnEventDescriptor itself that instrument considers leaking IMHO.

> Does its autorelease pool get released before you check for leaks?

You saw the stacktrace? The code runs within a block scheduled on a GCD queue and queues implicitly have an autorelease pool.

Whether it was drained already at that point? I don't know, but again, how would that matter? If there is an autorelease pool that sill has a reference, how would that be a leak? A leak is allocated memory to that no reference exists. Something in an autorelease pool has never been considered a leak by any tool I've ever used.

> What does your script do? Does it contain any AppleScript/Objective-C code?

I doubt that this is really relevant as nothing the script does or can do should cause a leak. Here's the script, full source (really, that's the whole script!):

tell application "System Events" get properties of every login item end tell

> Do you see the same leaks if you run the script in Script Editor or with osascript?

No, I don't, but who says these tools even use "NSAppleScript" at all?

> Can you attach the Instruments recording?

Not sure if I can, it gives quite a lot away from our software and I really don't know what you intend to find there.

By m.hanauska at Jan. 17, 2017, 6:22 p.m. (reply...)

Apple asked the following questions:

16-Nov-2016 07:02 PM

Do you retain returnEventDescriptor? Does its autorelease pool get released before you check for leaks?

What does your script do? Does it contain any AppleScript/Objective-C code?

Do you see the same leaks if you run the script in Script Editor or with osascript?

Can you attach the Instruments recording?

Please provide your response or results by updating your bug report. If uploading files, please compress first.

By m.hanauska at Jan. 17, 2017, 6:20 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!