[Top][All Lists]

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

[bug #59204] NSOperationQueue leak

From: Larry Campbell
Subject: [bug #59204] NSOperationQueue leak
Date: Sat, 10 Oct 2020 15:47:38 -0400 (EDT)
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15

Follow-up Comment #7, bug #59204 (project gnustep):

Actually the proposed fix creates (incidentally) a bug that causes NSOperation
threads never to exit!

-[NSOperationQueue _thread] (now) starts off like this (the
ENTER_POOL/LEAVE_POOL were recently added as part of the fix here):

  for (;;)
      /* We use a pool for each operation in case releasing the operation     
       * causes it to be deallocated, and the deallocation of the operation   
       * autoreleases something which needs to be cleaned up.                 
      NSOperation       *op;
      NSDate            *when;
      BOOL              found;

      when = [[NSDate alloc] initWithTimeIntervalSinceNow: 5.0];
      found = [internal->cond lockWhenCondition: 1 beforeDate: when];
      if (NO == found)
          break;        // Idle for 5 seconds ... exit thread.                

ENTER_POOL is a macro that expands to:

#define ENTER_POOL                      @autoreleasepool{do{

This is *extremely dangerous!*  The 'break' above in thread breaks from the do
loop started by ENTER_POOL, not from the for(;;) loop in _thread, which is
what was obviously intended, and what the code did before the ENTER_POOL was
added in commit 41badcb417.

I really don't understand why ENTER_POOl isn't defined as

#define ENTER_POOL                      @autoreleasepool{do{

and LEAVE_POOL as 

#define LEAVE_POOL                      }

This is safer, does not hijack 'break' and 'continue' statements between them,
and everything compiles fine this way (except for Tools/AGSHtml.m, which is
clearly confused about its break statement at line 1087).


Reply to this item at:


  Message sent via Savannah

reply via email to

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