Changeset 3852 for trunk


Ignore:
Timestamp:
Mar 17, 2014, 5:24:58 AM (11 years ago)
Author:
bird
Message:

sharedpm.c: Fixed leak of pTerm of processes which didn't send any termination notification to their parent. Make sure we get inherit data, even locked, when the process is being freed or turned into a zombie. Use DosVerityPidTid to quickly weed out embryo process structures of non-libc processes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libc/src/kNIX/os2/sharedpm.c

    r3796 r3852  
    55 *
    66 * Copyright (c) 2004 nickk
    7  * Copyright (c) 2004-2005 knut st. osmundsen <bird-src-spam@anduin.net>
     7 * Copyright (c) 2004-2014 knut st. osmundsen <bird-src-spam@anduin.net>
    88 *
    99 *
     
    514514            SPM_ASSERT_PTR_NULL(pProcess->pPrev);
    515515            SPM_ASSERT_PTR_NULL(pProcess->pNext);
    516             if (    pProcess->pidParent == pidParent
    517                 &&  pProcess->cReferences == 0
    518                 &&  uTimestamp - pProcess->uTimestamp >= 1*60*1000)
     516            if (   pProcess->pidParent == pidParent
     517                && pProcess->cReferences == 0
     518                && (   uTimestamp - pProcess->uTimestamp >= 1*60*1000
     519                    || (   uTimestamp - pProcess->uTimestamp >= 8000
     520                        && pProcess->pid != -1
     521                        && DosVerifyPidTid(pProcess->pid, 1) == ERROR_INVALID_PROCID)
     522                   )
     523               )
    519524            {
    520525                __LIBC_PSPMPROCESS      pProcessNext = pProcess->pNext;
     
    26732678    LIBCLOG_ENTER("pProcess=%p\n", (void *)pProcess);
    26742679    LIBC_ASSERT(pProcess->enmState != __LIBC_PROCSTATE_FREE);
     2680
    26752681    /*
    26762682     * Dereference it.
     
    26982704         */
    26992705        /* inherited data */
    2700         if (pProcess->pInherit)
    2701         {
    2702             spmFree(pProcess->pInherit);
     2706        void *pv = pProcess->pInheritLocked;
     2707        if (!pv)
     2708            pv = pProcess->pInherit;
     2709        if (pv)
     2710        {
    27032711            pProcess->pInherit = NULL;
     2712            pProcess->pInheritLocked = NULL;
     2713            spmFree(pv);
    27042714        }
    27052715
     
    28522862    {
    28532863        pProcess = pProcessBest;
    2854         LIBCLOG_MSG("Found my embryo %p (pidParent=%#x pid=%#x cReferences=%d uTimestamp=%04x)\n",
    2855                     (void *)pProcess, pProcess->pidParent, pProcess->pid, pProcess->cReferences, pProcess->uTimestamp);
     2864        LIBCLOG_MSG("Found my embryo %p (pidParent=%#x pid=%#x cReferences=%d uTimestamp=%04x pInherit=%p/%p)\n",
     2865                    (void *)pProcess, pProcess->pidParent, pProcess->pid, pProcess->cReferences, pProcess->uTimestamp, pProcess->pInherit, pProcess->pInheritLocked);
    28562866
    28572867        /* set data. */
     
    30413051                  pProcess->pvForkHandle, (void *)pProcess->pNext, (void *)pProcess->pPrev);
    30423052    /*
     3053     * Free inheritance info.
     3054     */
     3055    void *pv = pProcess->pInheritLocked;
     3056    if (!pv)
     3057        pv = pProcess->pInherit;
     3058    if (pv)
     3059    {
     3060        pProcess->pInherit = NULL;
     3061        pProcess->pInheritLocked = NULL;
     3062        spmFree(pv);
     3063    }
     3064
     3065    /*
    30433066     * Free signals.
    30443067     */
     
    30623085        pNotify = pNotify->pNext;
    30633086        spmFreeChildNotify(pFree);
     3087    }
     3088
     3089    /*
     3090     * Parent notification.
     3091     */
     3092    if (pProcess->pTerm)
     3093    {
     3094        spmFreeChildNotify(pProcess->pTerm);
     3095        pProcess->pTerm = NULL;
    30643096    }
    30653097
     
    34423474
    34433475        /*
    3444          * Free embryos which are more than 5 min old.
     3476         * Free embryos which are more than 5 min old or which processes no longer exists.
    34453477         */
    34463478        uTimestamp = spmTimestamp();
     
    34543486                SPM_ASSERT_PTR_NULL(pProcess->pPrev);
    34553487                if (    pProcess->cReferences == 0
    3456                     &&  uTimestamp - pProcess->uTimestamp >= 5*60*1000)
     3488                    &&  (   uTimestamp - pProcess->uTimestamp >= 5*60*1000
     3489                         || (   pProcess->pid != -1
     3490                             && DosVerifyPidTid(pProcess->pid, 1) == ERROR_INVALID_PROCID)
     3491                        )
     3492                    )
    34573493                {
    34583494                    __LIBC_PSPMPROCESS      pProcessNext = pProcess->pNext;
Note: See TracChangeset for help on using the changeset viewer.