Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#59498 closed defect (fixed)

openssh @8.1p1_2: __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug

Reported by: iefdev (Eric F) Owned by: Ionic (Mihai Moldovan)
Priority: Low Milestone:
Component: ports Version: 2.6.2
Keywords: Cc:
Port: openssh

Description

Thanks! for the last commit (41d935f). :+1:

To complete the test with my test key, I added the key now.

The functionality is all ok, but the output is debug('ish) - it comes with some noise.

Adding the key:

$ ssh-add -K ~/.ssh/id_test
objc[80665]: Object 0x7f8d79c2be20 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d79c2c3f0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d79c2cc10 of class __NSCFDictionary autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d79c2d520 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d79c2d4a0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d79c2d4d0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d79c2d590 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d79c2d5f0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d79c2dae0 of class NSConcreteMutableData autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
Enter passphrase for ~/.ssh/id_test: 
objc[80665]: Object 0x7f8d7b800090 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d7b800270 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d7b800140 of class __NSCFDictionary autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d7b800820 of class __NSCFDictionary autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d7b8008e0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d7b800b40 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d7b800b70 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d7b8000c0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d7b8000f0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d7b800430 of class NSConcreteMutableData autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d79c4f5f0 of class NSConcreteData autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80665]: Object 0x7f8d79c37210 of class __NSCFDictionary autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
Identity added: ~/.ssh/id_test (Eric F :: 2019-10-26)

Deleting the key:

$ ssh-add -Kd ~/.ssh/id_test
objc[80694]: Object 0x7fe528c2bbe0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80694]: Object 0x7fe528c2c270 of class __NSCFDictionary autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[80694]: Object 0x7fe52aa07550 of class __NSCFData autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
Identity removed: ~/.ssh/id_test (Eric F :: 2019-10-26)


Bug? …or just noise?

Change History (6)

comment:1 Changed 5 years ago by Ionic (Mihai Moldovan)

Cc: Ionic removed
Owner: set to Ionic
Priority: NormalLow
Status: newaccepted

Should be just noise, I guess.

In essence, libobjc complains about autorelease being used (typically after something goes out of scope) without an autorelease pool being available. Normally the ownership is transferred to that pool and the garbage collector clears it out periodically (that might not hold for ARC code, but 10.6 doesn't have ARC).

The weird part is that Cocoa itself is supposed to install an autorelease pool in the main (but not other) threads and as far as I know ssh-add isn't even multi-threaded.

We also don't link against Cocoa, so there's that.

Maybe I'll just need to add an autorelease pool for older systems (10.7 and below?), even though 10.7 should have full ARC support already...

comment:2 Changed 5 years ago by iEFdev

I was thinking of the edits we made to the dictionary, etc - if it perhaps was related to that, but noise is ok (if it can be muted).

After seeing this: #59497 (there was no cc to you in that one), I thought perhaps some debug trigger maybe was added/activated (on purpose or just coincidentally) - since each line end with: … to debug. If it's just noise, maybe it's just enough to turn the debug off if that's the case.

comment:3 Changed 5 years ago by Mihai Moldovan <ionic@…>

Resolution: fixed
Status: acceptedclosed

In 439a81a91ea103342b41c8a4b091843615e540b2/macports-ports (master):

net/openssh: potentially fix memory leaks on 10.7-.

Users on 10.7- experienced a set of messages along those lines while
executing ssh-add:

objc[<bumber>]: Object <address> of class NSCFString autoreleased with
no pool in place - just leaking - break on objc_autoreleaseNoPool() to
debug

Such messages scare users, even though, strictly speaking, memory leaks
in ssh-add should be benign. This application has a short life time and
(almost never) processes large amounts of data, so even if memory is
leaked, the impact of these leaks should be ignorable.

The *reason* for this message is mystifying me, since I cannot reproduce
this on 10.9.

Generally, Cocoa only creates one global autorelease pool for the main
thread, but not other threads. ssh-add itself shouldn't be
multi-threaded as far as I could see (which might be wrong), so this
can't be the correct explanation.

It looks like global autorelease pools are also not generated for
Foundation-only applications, which essentially is happening here.

The mystery is that at least 10.7 should already have proper ARC support
and hence applications should not use NSAutoreleasePool directly anyway,
but let ARC handle this stuff or only use local
@autoreleasepool { blocks }, which are equally handled by ARC.

For some reason, this doesn't seem to happen here.

Let's work around this issue by creating an NSAutoreleasePool instance
at the top of each function in keychain.m (the easy part) and drain the
pool before exiting the function (the not-so-easy part, because most
functions have multiple exit points).

The code looks a bit ugly that way, but it should rid us of the nasty
leak message that is confusing users.

Fixes: #59498

comment:4 Changed 5 years ago by Ionic (Mihai Moldovan)

Please see if that does anything beneficial (and if it even builds successfully).

I've tried to explain what is (possibly?) happening and that a memory leak in ssh-add is pretty benign (mostly because it's a single application with a small process life time), but if this works and gets rid of the messages, even better.

comment:5 in reply to:  4 Changed 5 years ago by iEFdev

Replying to Ionic:

Please see if that does anything beneficial (and if it even builds successfully).

I've tried to explain what is (possibly?) happening and that a memory leak in ssh-add is pretty benign (mostly because it's a single application with a small process life time), but if this works and gets rid of the messages, even better.

Thanks! It built fine, and no noise. 👍 ✨

$ port installed openssh
The following ports are currently installed:
  openssh @8.1p1_3+gsskex+kerberos5+ldns+xauth (active)
$ ssh-add -K ~/.ssh/id_test 
Enter passphrase for ~/.ssh/id_test: 
Identity added: ~/.ssh/id_test (Eric F :: 2019-11-02)
$ ssh-add -Kd ~/.ssh/id_test 
Identity removed: ~/.ssh/id_test (Eric F :: 2019-11-02)


OT: For the symlink… If it was renamed to security in 10.6+ - maybe something like this?:

    platform darwin {
        # create link to /usr/include/pam on systems pre OS X 10.6. 
        if {([vercmp ${os.major} 9] <=  0)} {
            pre-configure {
                xinstall -d ${workpath}/include
                file delete ${workpath}/include/security
                ln -s /usr/include/pam ${workpath}/include/security
            }
        }
    }

comment:6 Changed 5 years ago by Ionic (Mihai Moldovan)

I honestly just forgot about that. Will hopefully remember to get rid of it with the next revbump. The broken symlink is something very minor - it doesn't break building or usage.

Note: See TracTickets for help on using tickets.