bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #44240] NSThread leaks a run loop if NSFileHandle -finalize is call


From: Wolfgang Lux
Subject: [bug #44240] NSThread leaks a run loop if NSFileHandle -finalize is called during deallocation
Date: Fri, 13 Feb 2015 17:58:18 +0000
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_7_5; en-US) AppleWebKit/533.21.1+(KHTML, like Gecko, Safari/533.19.4) Version/5.11.1 OmniWeb/622.18.0

URL:
  <http://savannah.gnu.org/bugs/?44240>

                 Summary: NSThread leaks a run loop if NSFileHandle -finalize
is called during deallocation
                 Project: GNUstep
            Submitted by: wlux
            Submitted on: Fr 13 Feb 2015 17:58:17 GMT
                Category: None
                Severity: 3 - Normal
              Item Group: None
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any

    _______________________________________________________

Details:

I've come across a bug where my program was leaking file descriptors. It turns
out that this bug was happening if NSFileHandle -finalize is called while the
NSThread -dealloc method is called, e.g., because a NSFileHandle object is
released while the target or argument attributes of the NSThread instance are
deallocated.
This happens because the thread's run loop is deallocated early on in the
-dealloc method, in particular before the _target and _arg attributes are
released. The NSFileHandle -finalize method, on the other hand, calls
-ignoreReadDescriptor and -ignoreWriteDescriptor and both methods ask for the
current thread's run loop. Thus, if -finalize is called from within NSThread
-dealloc, a new run loop is created and saved in the thread object, but then
never gets released.
You can see this with the attached test program. Compile the attached program
with the commands 
  gcc `gnustep-config --objc-flags` -c Tester.m 
  gcc `gnustep-config --objc-flags` -o Tester Tester.o `gnustep-config
--base-libs` 
(use clang instead of gcc if you wish so). Then run ./Tester from the command
line. The program displays a prompt where you can enter a file name. For each
name that you enter, the program reads the named file in a background thread
(starting after a delay of 1 second) and once finished it prints the size of
the file and the memory statistics. Watch how a GSRunLoopThreadInfo and
NSRunLoop leak on each iteration after you have entered the third filename.



    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Fr 13 Feb 2015 17:58:17 GMT  Name: Tester.m  Size: 3kB   By: wlux

<http://savannah.gnu.org/bugs/download.php?file_id=33064>

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?44240>

_______________________________________________
  Nachricht gesendet von/durch Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]