Changeset 186 for trunk


Ignore:
Timestamp:
Nov 9, 2008, 9:45:46 PM (17 years ago)
Author:
dmik
Message:

Kernel: QPrcess: Make sure the pipe key is not used after the assoiated pipe is closed (ticket:51).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel/qprocess_pm.cpp

    r168 r186  
    193193    void closeHandles()
    194194    {
    195         if( pipeStdin != HP_NULL ) {
     195        if( pipeStdin != HP_NULL ) {
    196196            DosDisConnectNPipe( pipeStdin );
    197197            DosClose( pipeStdin );
    198198            pipeStdin = HP_NULL;
    199         }
     199        }
    200200        closePipe( &stdout );
    201201        closePipe( &stderr );
     
    586586            if ( proc == pipeKeys.find( key ) ) {
    587587#if defined(QT_QPROCESS_DEBUG)
    588             qDebug( "QProcessMonitor::WM_U_PIPE_CLOSE: proc=%p (%s/%s) d=%p "
    589                     "key=%04hX",
    590                     proc, proc->name(), proc->className(), proc->d, key );
     588                qDebug( "QProcessMonitor::WM_U_PIPE_CLOSE: proc=%p (%s/%s) d=%p "
     589                        "key=%04hX",
     590                        proc, proc->name(), proc->className(), proc->d, key );
    591591#endif
    592592                QProcessPrivate *d = proc->d;
     
    645645    // 1. If procesMonitor is NULL, it which means we're somewhere inside
    646646    //    the QApplication destruction procedure.
    647     // 2. If pipe->key us KEY_NULL, it means GUI thread has already processed
     647    // 2. If pipe->key is KEY_NULL, it means GUI thread has already processed
    648648    //    the WM_U_PIPE_CLOSE message and we're free to access fields w/o a
    649649    //    lock. pipe->key is assigned only on the GUI thread, so it's safe
     
    686686        // the client's end of pipe has been closed, so close our end as well
    687687        if ( processMonitor && pipe->key != KEY_NULL ) {
    688             // WM_U_PIPE_CLOSE has been posted but not yet processed
    689             processMonitor->removeProcess( this, pipe );
    690         }
    691         closePipe( pipe );
     688            // WM_U_PIPE_CLOSE has been posted but not yet processed: do
     689            // nothing in this case and let it do the close job. This is vital
     690            // since if we close the pipe now then it's possible that another
     691            // QProcess instance created in the meantime will get a pipe with
     692            // the same handle from the system (and therefore with the same key)
     693            // so our pending WM_U_PIPE_CLOSE message will attempt to close an
     694            // invalid (foreign) pipe
     695        }
     696        else
     697            closePipe( pipe );
    692698    }
    693699       
Note: See TracChangeset for help on using the changeset viewer.