Changeset 1836


Ignore:
Timestamp:
Jul 15, 2015, 2:48:14 AM (10 years ago)
Author:
Gregg Young
Message:

Fix trap in collector if a pci-pszFileName = NullStr and fix heap corruption problem and its related traps. This code reverts John double free fix. Ticket [551][555]

Location:
trunk/dll
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/collect.c

    r1803 r1836  
    8989  02 May 15 GKY Changes to allow a JAVA executable object to be created using "Real object"
    9090                menu item on a jar file.
     91  14 Jun 15 GKY Changes to prevent trap in Filter
    9192
    9293***********************************************************************/
     
    748749            }
    749750            else {
    750               // Update OK
    751               if (Filter((PMINIRECORDCORE) pciUpd, (PVOID) & dcd->mask)) {
     751              // Update OK
     752              DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
     753              if (dcd && Filter((PMINIRECORDCORE) pciUpd, (PVOID) & dcd->mask)) {
    752754                pciUpd->rc.flRecordAttr &= ~CRA_FILTERED;       // Ensure visible
    753755                // 2011-05-29 SHL fixme to check fail
    754756                WinSendMsg(dcd->hwndCnr, CM_INVALIDATERECORD, MPVOID,
    755757                           MPFROM2SHORT(0, CMA_REPOSITION | CMA_ERASE));
    756               }
     758              }
     759              DosReleaseMutexSem(hmtxFiltering);
    757760            }
    758761            ulMaxFiles--;               // No insert needed
     
    913916                              TRUE)) {
    914917              // Already in container
    915               pci = UpdateCnrRecord(dcd->hwndCnr, fullname, FALSE, dcd);
    916               if (Filter((PMINIRECORDCORE) pci, (PVOID) & dcd->mask)) {
     918              pci = UpdateCnrRecord(dcd->hwndCnr, fullname, FALSE, dcd);
     919              DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
     920              if (dcd && Filter((PMINIRECORDCORE) pci, (PVOID) & dcd->mask)) {
    917921                pci->rc.flRecordAttr &= ~CRA_FILTERED;
    918922                WinSendMsg(dcd->hwndCnr, CM_INVALIDATERECORD, MPVOID,
    919923                           MPFROM2SHORT(0, CMA_REPOSITION | CMA_ERASE));
    920               }
     924              }
     925              DosReleaseMutexSem(hmtxFiltering);
    921926            }
    922927            else if (IsFullName(fullname) &&
     
    11681173      DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
    11691174      free(dcd);
     1175      dcd = NULL;
    11701176      DosReleaseMutexSem(hmtxFiltering);
    11711177#     ifdef FORTIFY
     
    14251431              p = pci->pszFileName;
    14261432            else {
    1427               if (!pci->pszFileName)
    1428                 Runtime_Error(pszSrcFile, __LINE__, "pci->pszFileName NULL for %p", pci);
    1429               p = strrchr(pci->pszFileName, '\\');
     1433              if (!pci->pszFileName) {
     1434                Runtime_Error(pszSrcFile, __LINE__, "pci->pszFileName NULL for %p", pci);
     1435                return 0;
     1436              }
     1437              p = strrchr(pci->pszFileName, '\\');
    14301438              if (p) {
    14311439                if (*(p + 1))
     
    21282136            // 2013-12-13 SHL Allow nul pszFileName
    21292137            pci = (PCNRITEM) CurrentRecord(hwnd);
    2130             if (pci && pci->pszFileName && ~pci->attrFile & FILE_DIRECTORY) {
     2138            if (pci && pci->pszFileName != NullStr && ~pci->attrFile & FILE_DIRECTORY) {
    21312139              p = strrchr(pci->pszFileName, '\\');
    21322140              if (p) {
     
    28152823      case CN_ENDEDIT:
    28162824        {
    2817           MRESULT mre;
    2818 
    2819           mre = CnrDirectEdit(hwnd, msg, mp1, mp2);
     2825          MRESULT mre;
     2826
     2827          mre = CnrDirectEdit(hwnd, msg, mp1, mp2);
    28202828          if (mre != (MRESULT) - 1)
    28212829            return mre;
  • trunk/dll/comp.c

    r1686 r1836  
    9191                Added saymsg2 for this purpose
    9292  10 Mar 13 GKY Fixes to snapshot file.
     93  14 Jun 15 GKY Changes to prvenet access violations when cmp is freed
    9394
    9495***********************************************************************/
     
    944945#    endif
    945946  }
    946   else
     947  else {
     948    DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
    947949    free(cmp);
     950    cmp = NULL;
     951    DosReleaseMutexSem(hmtxFiltering);
     952  }
    948953}
    949954
     
    19941999            pcil->crtime.seconds = filesl[l]->crtime.twosecs * 2;
    19952000            pcil->crtime.minutes = filesl[l]->crtime.minutes;
    1996             pcil->crtime.hours = filesl[l]->crtime.hours;
    1997             if (*cmp->dcd.mask.szMask) {
     2001            pcil->crtime.hours = filesl[l]->crtime.hours;
     2002            DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
     2003            if (cmp && *cmp->dcd.mask.szMask) {
    19982004              if (!Filter((PMINIRECORDCORE)pcil, (PVOID)&cmp->dcd.mask)) {
    19992005                pcil->rc.flRecordAttr |= CRA_FILTERED;
    20002006                pcir->rc.flRecordAttr |= CRA_FILTERED;
    2001               }
    2002             }
     2007              }
     2008            }
     2009            DosReleaseMutexSem(hmtxFiltering);
    20032010          } // if on left
    20042011
     
    20362043            pcir->crtime.minutes = filesr[r]->crtime.minutes;
    20372044            pcir->crtime.hours = filesr[r]->crtime.hours;
    2038             // Bypass check if already filtered on left side
    2039             if (~pcir->rc.flRecordAttr & CRA_FILTERED &&
     2045            // Bypass check if already filtered on left side
     2046            DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
     2047            if (cmp && ~pcir->rc.flRecordAttr & CRA_FILTERED &&
    20402048                *cmp->dcd.mask.szMask) {
    20412049              if (!Filter((PMINIRECORDCORE)pcir, (PVOID)&cmp->dcd.mask)) {
    20422050                pcil->rc.flRecordAttr |= CRA_FILTERED;
    20432051                pcir->rc.flRecordAttr |= CRA_FILTERED;
    2044               }
    2045             }
     2052              }
     2053            }
     2054            DosReleaseMutexSem(hmtxFiltering);
    20462055          } // if on right
    20472056
     
    22412250    WinTerminate(hab);
    22422251  }
     2252  DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
    22432253  free(cmp);
     2254  cmp = NULL;
     2255  DosReleaseMutexSem(hmtxFiltering);
    22442256  DosPostEventSem(CompactSem);
    22452257
     
    25662578        // 01 Aug 07 SHL if field null or blank, we draw
    25672579        // fixme to document why - probably to optimize and bypass draw?
    2568         if (pci && (INT)pci != -1 && !*pci->pszFileName)
     2580        if (pci && (INT)pci != -1 && !*pci->pszFileName && pci->pszFileName != NullStr)
    25692581          return MRFROMLONG(TRUE);
    25702582      }
     
    35423554          WinSendMsg(cmp->dcd.hwndObject, WM_CLOSE, MPVOID, MPVOID);
    35433555      }
     3556      DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
    35443557      free(cmp);
     3558      cmp = NULL;
     3559      DosReleaseMutexSem(hmtxFiltering);
    35453560    }
    35463561    EmptyCnr(GetHwndLeft(hwnd));
  • trunk/dll/dircnrs.c

    r1807 r1836  
    9797#include <ctype.h>
    9898#include <limits.h>
     99//#include <malloc.h>                   // _msize _heapchk
    99100// #include <process.h>                 // _beginthread
    100101
     
    169170#include "pathutil.h"                   // AddBackslashToPath
    170171#include "copyf.h"                      // ignorereadonly
     172#if 0
     173#define  __PMPRINTF__
     174#include "PMPRINTF.H"
     175#endif
    171176
    172177// Data definitions
     
    791796      }
    792797      else
    793         *szFree = 0;
     798        *szFree = 0;
     799      DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
    794800      commafmt(tf, sizeof(tf), dcd->totalfiles);
    795801      CommaFmtULL(tb, sizeof(tb), dcd->ullTotalBytes, ' ');
     802      DosReleaseMutexSem(hmtxFiltering);
    796803      if (!fMoreButtons) {
    797804        sprintf(s, " [%s / %s]%s%s%s%s %s",
     
    873880      RemoveCnrItems(dcd->hwndCnr, NULL, 0, CMA_FREE | CMA_INVALIDATE | CMA_ERASE);
    874881      AdjustCnrColsForFSType(dcd->hwndCnr, dcd->directory, &dcd->ds, FALSE);
    875       dcd->ullTotalBytes = dcd->totalfiles =
    876         dcd->selectedfiles = dcd->selectedbytes = 0;
     882      DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
     883      dcd->ullTotalBytes = dcd->totalfiles = dcd->selectedfiles = dcd->selectedbytes = 0;
     884      DosReleaseMutexSem(hmtxFiltering);
    877885      WinSetDlgItemText(dcd->hwndClient, DIR_TOTALS, "0 / 0k");
    878886      WinSetDlgItemText(dcd->hwndClient, DIR_SELECTED, "0 / 0k");
     
    12201228      DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
    12211229      xfree(dcd, pszSrcFile, __LINE__);
     1230      dcd = NULL;
    12221231      DosReleaseMutexSem(hmtxFiltering);
    12231232      DosPostEventSem(CompactSem);
     
    14751484      cnri.pszCnrTitle = dcd->directory;
    14761485      WinSendMsg(hwnd,
    1477                  CM_SETCNRINFO, MPFROMP(&cnri), MPFROMLONG(CMA_CNRTITLE));
     1486                 CM_SETCNRINFO, MPFROMP(&cnri), MPFROMLONG(CMA_CNRTITLE));
     1487      DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
    14781488      dcd->totalfiles = cnri.cRecords;
    14791489      commafmt(tb, sizeof(tb), dcd->totalfiles);
    14801490      CommaFmtULL(tf, sizeof(tf), dcd->ullTotalBytes, 'K');
     1491      DosReleaseMutexSem(hmtxFiltering);
    14811492      sprintf(s, "%s / %s", tb, tf);
    14821493      WinSetDlgItemText(dcd->hwndClient, DIR_TOTALS, s);
     
    32583269          else {
    32593270
    3260             MRESULT mre;
    3261 
    3262             mre = CnrDirectEdit(hwnd, msg, mp1, mp2);
     3271            MRESULT mre;
     3272
     3273            mre = CnrDirectEdit(hwnd, msg, mp1, mp2);
    32633274            if (mre != (MRESULT) - 1)
    32643275              return mre;
     
    33043315            }
    33053316          }
    3306           if (!dcd->suspendview && hwndMain &&
     3317          if (!dcd->suspendview && hwndMain && pci->pszFileName != NullStr &&
    33073318              (pre->fEmphasisMask & CRA_CURSORED) &&
    33083319              (pci->rc.flRecordAttr & CRA_CURSORED) &&
     
    35133524    WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
    35143525    if (LastDir == hwnd)
    3515       LastDir = (HWND) 0;
     3526        LastDir = (HWND) 0;
     3527    DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
    35163528    if (dcd) {
    35173529      dcd->stopflag++;
     
    35333545                        SWP_RESTORE | SWP_SHOW | SWP_ACTIVATE | SWP_ZORDER);
    35343546      FreeList(dcd->lastselection);
    3535       DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
    3536       free(dcd);
    3537       DosReleaseMutexSem(hmtxFiltering);
    35383547      WinSetWindowPtr(hwnd, QWL_USER, NULL);
    35393548      DosPostEventSem(CompactSem);
    35403549    }
     3550    DosReleaseMutexSem(hmtxFiltering);
    35413551    WinDestroyWindow(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
    35423552                                    QW_PARENT));
     
    35553565    DirMenu = DirCnrMenu = FileMenu = (HWND) 0;
    35563566    EmptyCnr(hwnd);
     3567    DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
     3568    xfree(dcd, pszSrcFile, __LINE__);
     3569    dcd = NULL;
     3570    DosReleaseMutexSem(hmtxFiltering);
    35573571#   ifdef FORTIFY
    35583572    Fortify_LeaveScope();
  • trunk/dll/filldir.c

    r1814 r1836  
    107107  28 Jun 14 GKY Fix errors identified with CPPCheck
    108108  30 Aug 14 GKY Use saymsg2 for Suggest dialog
     109  14 Jun 15 GKY Changes to prevent trap in Filter, heap corruption and traps associated with it
    109110  19 Jun 15 JBS Ticket 514: Double free fix (which also fixes a memory leak)
    110111
     
    153154#include "pathutil.h"                   // AddBackslashToPath
    154155#include "tmrsvcs.h"                    // ITIMER_DESC
     156#if 0
     157#define  __PMPRINTF__
     158#include "PMPRINTF.H"
     159#endif
    155160
    156161VOID StubbyScanThread(VOID * arg);
     
    424429  BOOL fLoadSubjectForDrive = fLoadSubject && ~flags & DRIVE_NOLOADSUBJS;
    425430  BOOL fLoadLongNameForDrive = fLoadLongnames &&  //~flags & DRIVE_NOLONGNAMES &&
    426                                ~flags & DRIVE_NOLOADLONGS;
     431                               ~flags & DRIVE_NOLOADLONGS;
    427432  if (fLoadSubjectForDrive || fLoadLongNameForDrive) {
    428433    // Allocate space to hold GEA2s and .SUBJECT and .LONGNAME strings
    429     PGEA2LIST pgealist = xmallocz(sizeof(GEA2LIST) + sizeof(GEA2) + 64, pszSrcFile, __LINE__);
     434      PGEA2LIST pgealist = xmallocz(sizeof(GEA2LIST) + (sizeof(GEA2) * 2) + 32,
     435                                    pszSrcFile, __LINE__);
    430436    if (pgealist) {
    431437      APIRET rc;
     
    466472      //DbgMsg(pszSrcFile, __LINE__, "pgealist %p cbList %u", pgealist, pgealist->cbList);
    467473
    468       pfealist = xmallocz(4096, pszSrcFile, __LINE__);
     474      pfealist = xmallocz(65536, pszSrcFile, __LINE__);
    469475      if (pfealist) {
    470         pfealist->cbList = 4096;
     476        pfealist->cbList = 65536;
    471477        eaop.fpGEA2List = pgealist;
    472478        eaop.fpFEA2List = pfealist;
     
    514520            pfea = (PFEA2)((PSZ)pfea + pfea->oNextEntryOffset);
    515521          } // while
    516         }
     522        }
    517523        free(pfealist);
    518524      }
     
    688694  pci->rc.hptrIcon = hptr;
    689695
     696
    690697  // check to see if record should be visible
     698  DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
    691699  if (dcd && (*dcd->mask.szMask || dcd->mask.antiattr ||
    692700              ((dcd->mask.attrFile &
    693701                (FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY | FILE_ARCHIVED))
    694                !=
    695                (FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY | FILE_ARCHIVED))))
    696   {
     702               != (FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY | FILE_ARCHIVED)))) {
    697703    if (*dcd->mask.szMask || dcd->mask.antiattr) {
    698704      if (!Filter((PMINIRECORDCORE) pci, (PVOID) & dcd->mask))
    699         pci->rc.flRecordAttr |= CRA_FILTERED;
     705        pci->rc.flRecordAttr |= CRA_FILTERED;
    700706    }
    701707    else if ((!(dcd->mask.attrFile & FILE_HIDDEN) &&
     
    710716    }
    711717  }
     718  DosReleaseMutexSem(hmtxFiltering);
    712719
    713720  return pffb->cbFile + pci->easize;
     
    851858  pci->rc.hptrIcon = hptr;
    852859
     860  DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
    853861  if (dcd &&
    854862      (*dcd->mask.szMask || dcd->mask.antiattr ||
     
    858866    if (*dcd->mask.szMask || dcd->mask.antiattr) {
    859867      if (!Filter((PMINIRECORDCORE) pci, (PVOID) & dcd->mask))
    860         pci->rc.flRecordAttr |= CRA_FILTERED;
     868        pci->rc.flRecordAttr |= CRA_FILTERED;
    861869    }
    862870    else if ((!(dcd->mask.attrFile & FILE_HIDDEN) &&
     
    870878      pci->rc.flRecordAttr |= CRA_FILTERED;
    871879  }
     880  DosReleaseMutexSem(hmtxFiltering);
    872881
    873882  return pfsa4->cbFile + pci->easize;
     
    968977        pffbFile = paffbFound;
    969978        ulSelCnt = 0;
    970         for (;;) {
     979        for (;;) {
    971980          if (!*pffbFile->achName ||
    972981              (!filestoo && ~pffbFile->attrFile & FILE_DIRECTORY) ||
     
    989998          if (stopflag && *stopflag)
    990999            goto Abort;
    991           if (fSyncUpdates) {
     1000          if (fSyncUpdates) {
     1001            if (!WinIsWindow(WinQueryAnchorBlock(hwndCnr), hwndCnr)) {
     1002              ok = FALSE;
     1003              ullTotalBytes = 0;
     1004              break;
     1005            }
    9921006            pciFirst = WinSendMsg(hwndCnr, CM_ALLOCRECORD,
    9931007                                  MPFROMLONG(EXTRA_RECORD_BYTES),
     
    10051019              // Finish filling pci items
    10061020              for (x = 0; x < ulSelCnt; x++) {
    1007                 pffbFile = papffbSelected[x];
     1021                pffbFile = papffbSelected[x];
    10081022                ullBytes = FillInRecordFromFFB(hwndCnr, pci, pszFileSpec,
    10091023                                               pffbFile, partial, dcd);
     
    10391053            if (ok) {
    10401054              ullReturnBytes += ullTotalBytes;
    1041               ulReturnFiles += ulSelCnt;
     1055              ulReturnFiles += ulSelCnt;
     1056              DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
    10421057              if (dcd) {
    10431058                dcd->totalfiles += ulSelCnt;
    10441059                dcd->ullTotalBytes += ullTotalBytes;
    1045               }
     1060              }
     1061              DosReleaseMutexSem(hmtxFiltering);
    10461062            }
    10471063          } // if sync updates
     
    10981114          ULONG ulRecsToInsert;
    10991115
    1100           if (pci ==NULL) {
     1116          if (pci ==NULL) {
     1117            if (!WinIsWindow(WinQueryAnchorBlock(hwndCnr), hwndCnr)) {
     1118              ok = FALSE;
     1119              ullTotalBytes = 0;
     1120              break;
     1121            }
    11011122            ulRecsToInsert = cAffbTotal - x <  USHRT_MAX  ? cAffbTotal - x : USHRT_MAX;
    11021123            pciFirst = WinSendMsg(hwndCnr, CM_ALLOCRECORD,
    11031124                                  MPFROMLONG(EXTRA_RECORD_BYTES), MPFROMLONG(ulRecsToInsert));
    11041125
    1105             if (!pciFirst) {
     1126            if (!pciFirst) {
     1127              //ERRORID erridErrorCode = WinGetLastError(WinQueryAnchorBlock(hwndCnr));
     1128              //PmpfF(("Allocation failed %i", erridErrorCode));
    11061129              Win_Error(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__,
    11071130                        GetPString(IDS_CMALLOCRECERRTEXT));
     
    11181141              pci = pciFirst;
    11191142            }
    1120           }
     1143          }
    11211144          ullBytes = FillInRecordFromFFB(hwndCnr, pci, pszFileSpec,
    11221145                                         pffbFile, partial, dcd);
    11231146          pci = (PCNRITEM) pci->rc.preccNextRecord;
    11241147          ullTotalBytes += ullBytes;
    1125           // 15 Sep 09 SHL allow timed updates to see
     1148          // 15 Sep 09 SHL allow timed updates to see
     1149          DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
    11261150          if (dcd) {
    11271151            dcd->totalfiles = x;
    11281152            dcd->ullTotalBytes = ullTotalBytes;
    1129           }
     1153          }
     1154          DosReleaseMutexSem(hmtxFiltering);
    11301155          // Can not use offset since we have merged lists - this should be equivalent
    11311156          pffbFile = (PFILEFINDBUF4L)((PBYTE)pffbFile + sizeof(FILEFINDBUF4L));
    11321157
    1133           if (!IdleIfNeeded(&itdSleep, 30)) {
    1134             for (x = x+1; x < cAffbTotal; x++) {
     1158          if (!IdleIfNeeded(&itdSleep, 30)) {
     1159            for (x = x+1; x < cAffbTotal; x++) {
    11351160              ullBytes = FillInRecordFromFFB(hwndCnr, pci, pszFileSpec,
    11361161                                          pffbFile, partial, dcd);
    11371162              pci = (PCNRITEM) pci->rc.preccNextRecord;
    1138               ullTotalBytes += ullBytes;
     1163              ullTotalBytes += ullBytes;
     1164              DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
    11391165              if (dcd) {
    11401166                dcd->totalfiles = x;
    11411167                dcd->ullTotalBytes = ullTotalBytes;
    1142               }
    1143               pffbFile = (PFILEFINDBUF4L)((PBYTE)pffbFile + sizeof(FILEFINDBUF4L));
     1168              }
     1169              DosReleaseMutexSem(hmtxFiltering);
     1170              pffbFile = (PFILEFINDBUF4L)((PBYTE)pffbFile + sizeof(FILEFINDBUF4L));
    11441171              if (pci == NULL) {
    11451172                priority_normal();
     
    18321859VOID FreeCnrItemData(PCNRITEM pci)
    18331860{
     1861 
    18341862  if (pci->pszSubject) {
    18351863    if (pci->pszSubject != NullStr)
     
    18371865    pci->pszSubject = NULL;             // Catch illegal references
    18381866  }
    1839 
     1867 
    18401868  // 08 Sep 08 SHL Remove excess logic
    18411869  if (pci->pszLongName) {
     
    18441872    pci->pszLongName = NULL;            // Catch illegal references
    18451873  }
    1846 
     1874 
    18471875  // Bypass free if pszDisplayName points into pszFileName buffer
    18481876  // 05 Sep 08 SHL Correct pointer overlap compare logic
     
    18531881          pci->pszDisplayName >= pci->pszFileName + _msize(pci->pszFileName))
    18541882      {
    1855         free(pci->pszDisplayName);
     1883        free(pci->pszDisplayName);
    18561884      }
    18571885    }
     
    18591887  }
    18601888
    1861   if (pci->pszFileName) {
    1862     if (pci->pszFileName != NullStr) {
     1889#if 0 // 26 Sep 09 SHL debug dup free complaints
     1890  if (!pci->pszFileName)
     1891    Runtime_Error(pszSrcFile, __LINE__, "FreeCnrItemData attempting to free %p data twice", pci);
     1892  else {
     1893    if (pci->pszFileName != NullStr)
    18631894      free(pci->pszFileName);
    1864     }
    1865     pci->pszFileName = NULL;            // Catch illegal references and dup free attempts
    1866   }
    1867 
    1868 // 26 Mar 14 JBS Twice on the longname?
     1895    pci->pszFileName = NULL;            // Catch illegal references
     1896  }
     1897#else
     1898  {
     1899    #define HIST_COUNT 50
     1900    static struct {
     1901      PCNRITEM pci;
     1902      PSZ pszFileName;
     1903    } history[HIST_COUNT];
     1904    static volatile UINT iHistNdx;
     1905    UINT i;
     1906
     1907    if (!pci->pszFileName) {
     1908      // Looks like pci was already freed
     1909      // Try to locate original file name in history buffer
     1910      for (i = 0; i < HIST_COUNT && pci != history[i].pci; i++) { }     // Scan
     1911      if (i < HIST_COUNT) {
     1912        Runtime_Error(pszSrcFile, __LINE__, "FreeCnrItemData attempting to free %p data twice, fileName was %.260s",
     1913                      pci, history[i].pszFileName);
     1914      } else {
     1915        Runtime_Error(pszSrcFile, __LINE__, "FreeCnrItemData attempting to free %p data twice", pci);
     1916      }
     1917    }
     1918    else {
     1919      PSZ psz;
     1920      PSZ *ppsz;
     1921      // Grab a history slot
     1922      // This should work well enoungh to prevent MT/SMP conflicts
     1923      for (;;) {
     1924        i = iHistNdx;
     1925        if (++i >= HIST_COUNT)
     1926          i = 0;
     1927        if (++iHistNdx >= HIST_COUNT)
     1928          iHistNdx = 0;
     1929        if (i == iHistNdx) break;
     1930      }
     1931      ppsz = &history[iHistNdx].pszFileName;
     1932      psz = *ppsz;
     1933      if (psz)
     1934        free(psz);
     1935      if (pci->pszFileName && pci->pszFileName != NullStr)
     1936        *ppsz = strdup(pci->pszFileName);
     1937      else
     1938        *ppsz = NULL;
     1939      history[iHistNdx].pci = pci;
     1940      if (pci->pszFileName != NullStr)
     1941        free(pci->pszFileName);
     1942      pci->pszFileName = NULL;          // Catch illegal references and dup free attempts
     1943    }
     1944  }
     1945
     1946
     1947#endif
     1948
    18691949  // 08 Sep 08 SHL Remove excess logic
    18701950  if (pci->pszLongName) {
     
    19432023{
    19442024  INT remaining = usCnt;
     2025  BOOL bIdlePrioritySet = FALSE;
     2026// #define RCI_ITEMS_PER_TIMER_CHECK (10)
     2027// 10 seems a very conservative number
     2028//   USHORT usTimerCheckCountdown       = RCI_ITEMS_PER_TIMER_CHECK;
    19452029  PCNRITEM pci;
    19462030  ITIMER_DESC itdSleep = { 0 };         // 30 May 11 GKY
     
    19662050      InitITimer(&itdSleep, 500);
    19672051      while (pci) {
    1968         FreeCnrItemData(pci);
     2052        FreeCnrItemData(pci);
     2053        pci = (PCNRITEM)pci->rc.preccNextRecord;
     2054        if (!pci)
     2055          break;
    19692056        if (remaining && --remaining == 0)
    19702057          break;
    1971         pci = (PCNRITEM)WinSendMsg(hwnd, CM_QUERYRECORD, (MPARAM)pci,
    1972                                    MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
    1973         if (pci && !IdleIfNeeded(&itdSleep, 30)) {
    1974           // Finishing in idle mode
    1975           while (pci) {
    1976             FreeCnrItemData(pci);
    1977             if (remaining && --remaining == 0)
    1978               break;
    1979             pci = (PCNRITEM)WinSendMsg(hwnd, CM_QUERYRECORD, (MPARAM)pci,
    1980                                    MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
    1981 
    1982           }
    1983           priority_normal();
    1984           break;
     2058        if (!bIdlePrioritySet /* && --usTimerCheckCountdown == 0 */) {
     2059          bIdlePrioritySet = !IdleIfNeeded(&itdSleep, 30);
     2060//           usTimerCheckCountdown = RCI_ITEMS_PER_TIMER_CHECK;
    19852061        }
    19862062      } // while
     2063      if (bIdlePrioritySet)
     2064        priority_normal();
     2065
    19872066      DosPostEventSem(CompactSem);
    19882067    }
    19892068  }
     2069
     2070  // DbgMsg(pszSrcFile, __LINE__, "RemoveCnrItems %p %u %s", pci, usCnt, pci->pszFileName);
    19902071
    19912072  if (remaining != - 1) {
     
    19952076    }
    19962077  }
     2078
    19972079  return remaining;
    19982080}
  • trunk/dll/filter.c

    r1797 r1836  
    2424  30 Aug 14 GKY Add semaphore hmtxFiltering to prevent freeing dcd while filtering. Prevents
    2525                a trap when FM2 is shutdown while directory containers are still populating
     26  14 Jun 15 GKY Changes to prevent trap in Filter
    2627
    2728***********************************************************************/
     
    8384  CHAR *file;
    8485
    85   DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
    8686  if (!mask) {
    87     DosReleaseMutexSem(hmtxFiltering);
    8887    return TRUE;
    8988  } // No mask data
     
    9493  if (!(*(pci->pszFileName + 3))
    9594      || mask->fShowDirs && (pci->attrFile & FILE_DIRECTORY)) {
    96     DosReleaseMutexSem(hmtxFiltering);
    9795    return TRUE;
    9896  }
     
    103101      (~mask->attrFile & FILE_ARCHIVED && pci->attrFile & FILE_ARCHIVED) ||
    104102      (~mask->attrFile & FILE_DIRECTORY && pci->attrFile & FILE_DIRECTORY)) {
    105     DosReleaseMutexSem(hmtxFiltering);
    106103    return FALSE;
    107104  }
     
    112109      (mask->antiattr & FILE_ARCHIVED && ~pci->attrFile & FILE_ARCHIVED) ||
    113110      (mask->antiattr & FILE_DIRECTORY && ~pci->attrFile & FILE_DIRECTORY)) {
    114     DosReleaseMutexSem(hmtxFiltering);
    115111    return FALSE;
    116112  }
    117113
    118114  if (mask && !*mask->szMask) {
    119     DosReleaseMutexSem(hmtxFiltering);
    120115    return TRUE;
    121116  }// No masks
     
    133128    BOOL wild = wildcard(strchr(mask->szMask, '\\') || strchr(mask->szMask, ':') ?
    134129                         pci->pszFileName : file, mask->szMask, FALSE);
    135     DosReleaseMutexSem(hmtxFiltering);
    136130    return wild;
    137131  }
     
    139133  // Have multiple mask strings
    140134  matched = FALSE;
    141   for (x = 0; mask->pszMasks[x]; x++) {
     135  for (x = 0; x < 26 && mask->pszMasks[x]; x++) {
    142136    if (*mask->pszMasks[x]) {
    143137      if (*mask->pszMasks[x] != '/') {
     
    164158    }
    165159  } // for
    166   DosReleaseMutexSem(hmtxFiltering);
    167160  return matched;
    168161}
Note: See TracChangeset for help on using the changeset viewer.