Changeset 1308 for trunk/dll


Ignore:
Timestamp:
Dec 1, 2008, 12:40:08 AM (17 years ago)
Author:
Steven Levine
Message:

FreeCnrItemData: optimize and always NULL pointers
StubbyScanThread: restore else - we want all drives listed
FreeCnrItemData: report double free with Runtime_Error

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/filldir.c

    r1299 r1308  
    5555  24 Nov 08 GKY Add StubyScanThread to treecnr scan/rescan drives all on separate threads
    5656  24 Nov 08 GKY Replace 4 pass drive scan code with StubyScanThread multithread scan
     57  28 Nov 08 SHL FreeCnrItemData: optimize and always NULL pointers
     58  28 Nov 08 SHL StubbyScanThread: add else lost in translation
     59  30 Nov 08 SHL StubbyScanThread: restore else - we want all drives listed
     60  30 Nov 08 SHL FreeCnrItemData: report double free with Runtime_Error
    5761
    5862***********************************************************************/
     
    9296#include "wrappers.h"                   // xDosFindNext
    9397#include "init.h"                       // GetTidForWindow
    94 #include "common.h"                     // IncrThreadUsage
     98#include "common.h"                     // IncrThreadUsage
    9599
    96100VOID StubbyScanThread(VOID * arg);
     
    109113CHAR *FM3Tools;
    110114CHAR *WPProgram;
    111 volatile INT  StubbyScanCount;
     115volatile INT StubbyScanCount;
    112116
    113117typedef struct {
    114 
    115118  PCNRITEM    pci;
    116   HWND        hwndCnr;                //hwnd you want the message posted to
     119  HWND        hwndCnr;                  // hwnd you want the message posted to
    117120  HWND        hwndDrivesList;
    118121  BOOL        RamDrive;
    119 
    120122}
    121123STUBBYSCAN;
     
    192194#  endif
    193195
    194   StubbyScan = (STUBBYSCAN *) arg;
    195   if (StubbyScan &&StubbyScan->pci && StubbyScan->pci->pszFileName && StubbyScan->hwndCnr) {
     196  StubbyScan = (STUBBYSCAN *)arg;
     197  if (StubbyScan && StubbyScan->pci && StubbyScan->pci->pszFileName && StubbyScan->hwndCnr) {
    196198    thab = WinInitialize(0);
    197199    if (thab) {
    198200      hmq = WinCreateMsgQueue(thab, 0);
    199201      if (hmq) {
    200         IncrThreadUsage();
    201         priority_normal();
    202         StubbyScanCount ++;
    203         ret = Stubby(StubbyScan->hwndCnr, StubbyScan->pci);
    204         if (ret == 0 && !StubbyScan->RamDrive) {
    205           if (WinIsWindow((HAB)0, StubbyScan->hwndCnr))
    206             WinSendMsg(StubbyScan->hwndCnr,
    207                        CM_INVALIDATERECORD,
    208                        MPFROMP(&StubbyScan->pci),
    209                        MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
    210         }
    211         if (WinIsWindow((HAB)0, StubbyScan->hwndDrivesList))
    212           WinSendMsg(StubbyScan->hwndDrivesList,
    213                      LM_INSERTITEM,
    214                      MPFROM2SHORT(LIT_SORTASCENDING, 0),
    215                      MPFROMP(StubbyScan->pci->pszFileName));
    216         StubbyScanCount --;
    217         WinDestroyMsgQueue(hmq);
     202        IncrThreadUsage();
     203        priority_normal();
     204        StubbyScanCount++;
     205        ret = Stubby(StubbyScan->hwndCnr, StubbyScan->pci);
     206        if (ret == 0 && !StubbyScan->RamDrive) {
     207          if (WinIsWindow((HAB)0, StubbyScan->hwndCnr))
     208            WinSendMsg(StubbyScan->hwndCnr,
     209                       CM_INVALIDATERECORD,
     210                       MPFROMP(&StubbyScan->pci),
     211                       MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
     212        }
     213        if (WinIsWindow((HAB)0, StubbyScan->hwndDrivesList)) {
     214          WinSendMsg(StubbyScan->hwndDrivesList,
     215                     LM_INSERTITEM,
     216                     MPFROM2SHORT(LIT_SORTASCENDING, 0),
     217                     MPFROMP(StubbyScan->pci->pszFileName));
     218        }
     219        StubbyScanCount--;
     220        WinDestroyMsgQueue(hmq);
    218221      }
    219222      DecrThreadUsage();
     
    15501553    STUBBYSCAN *StubbyScan;
    15511554    HWND hwndDrivesList = WinWindowFromID(WinQueryWindow(hwndParent, QW_PARENT),
    1552                                           MAIN_DRIVELIST);
     1555                                          MAIN_DRIVELIST);
    15531556
    15541557    //AddDrive = TRUE;
    15551558    pci = (PCNRITEM) WinSendMsg(hwndCnr,
    1556                                 CM_QUERYRECORD,
    1557                                 MPVOID,
    1558                                 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
     1559                                CM_QUERYRECORD,
     1560                                MPVOID,
     1561                                MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
    15591562
    15601563    while (pci && (INT)pci != -1) {
    15611564      StubbyScan = xmallocz(sizeof(STUBBYSCAN), pszSrcFile, __LINE__);
    15621565      if (!StubbyScan)
    1563         break;
     1566        break;
    15641567      StubbyScan->pci = pci;
    15651568      StubbyScan->hwndCnr = hwndCnr;
     
    15671570      StubbyScan->RamDrive = FALSE;
    15681571      pciNext = (PCNRITEM) WinSendMsg(hwndCnr,
    1569                                       CM_QUERYRECORD,
    1570                                       MPFROMP(pci),
    1571                                       MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
     1572                                      CM_QUERYRECORD,
     1573                                      MPFROMP(pci),
     1574                                      MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
    15721575      if (~pci->flags & RECFLAGS_ENV) {
    1573         ULONG drvNum = toupper(*pci->pszFileName) - 'A';        // 0..25
    1574         if (drvNum == ulCurDriveNum || drvNum >= 2) {
    1575           ULONG flags = driveflags[drvNum];     // Speed up
    1576           if (~flags & DRIVE_INVALID &&
    1577               ~flags & DRIVE_NOPRESCAN &&
    1578               (!fNoRemovableScan || ~flags & DRIVE_REMOVABLE))
    1579           {
    1580             if (DRIVE_RAMDISK)
    1581               StubbyScan->RamDrive = TRUE;
    1582             rc = _beginthread(StubbyScanThread, NULL, 65536, StubbyScan);
    1583             if (rc == -1)
    1584               Runtime_Error(pszSrcFile, __LINE__,
    1585                             GetPString(IDS_COULDNTSTARTTHREADTEXT));
    1586           } // if drive for scanning
    1587           else
    1588             WinSendMsg(hwndDrivesList,
    1589                        LM_INSERTITEM,
    1590                        MPFROM2SHORT(LIT_SORTASCENDING, 0),
    1591                        MPFROMP(pci->pszFileName));
    1592         }
    1593         else {
    1594           WinSendMsg(hwndCnr,
    1595                      CM_INVALIDATERECORD,
    1596                      MPFROMP(&pci),
    1597                      MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
    1598           WinSendMsg(hwndDrivesList,
    1599                      LM_INSERTITEM,
    1600                      MPFROM2SHORT(LIT_SORTASCENDING, 0),
    1601                      MPFROMP(pci->pszFileName));
    1602         }
     1576        ULONG drvNum = toupper(*pci->pszFileName) - 'A';        // 0..25
     1577        if (drvNum == ulCurDriveNum || drvNum >= 2) {
     1578          ULONG flags = driveflags[drvNum];     // Speed up
     1579          if (~flags & DRIVE_INVALID &&
     1580              ~flags & DRIVE_NOPRESCAN &&
     1581              (!fNoRemovableScan || ~flags & DRIVE_REMOVABLE))
     1582          {
     1583            if (DRIVE_RAMDISK)
     1584              StubbyScan->RamDrive = TRUE;
     1585            rc = _beginthread(StubbyScanThread, NULL, 65536, StubbyScan);
     1586            if (rc == -1)
     1587              Runtime_Error(pszSrcFile, __LINE__,
     1588                            GetPString(IDS_COULDNTSTARTTHREADTEXT));
     1589          } // if drive for scanning
     1590          else
     1591            WinSendMsg(hwndDrivesList,
     1592                       LM_INSERTITEM,
     1593                       MPFROM2SHORT(LIT_SORTASCENDING, 0),
     1594                       MPFROMP(pci->pszFileName));
     1595        }
     1596        else {
     1597          WinSendMsg(hwndCnr,
     1598                     CM_INVALIDATERECORD,
     1599                     MPFROMP(&pci),
     1600                     MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
     1601          WinSendMsg(hwndDrivesList,
     1602                     LM_INSERTITEM,
     1603                     MPFROM2SHORT(LIT_SORTASCENDING, 0),
     1604                     MPFROMP(pci->pszFileName));
     1605        }
    16031606      }
    16041607      pci = pciNext;
     
    17391742VOID FreeCnrItemData(PCNRITEM pci)
    17401743{
    1741   PSZ psz;
    1742   // DbgMsg(pszSrcFile, __LINE__, "FreeCnrItemData %p", pci);
    1743 
    1744   if (pci->pszSubject && pci->pszSubject != NullStr) {
    1745     psz = pci->pszSubject;
     1744  if (pci->pszSubject) {
     1745    if (pci->pszSubject != NullStr)
     1746      free(pci->pszSubject);
    17461747    pci->pszSubject = NULL;             // Catch illegal references
    1747     free(psz);
    17481748  }
    17491749
    17501750  // 08 Sep 08 SHL Remove excess logic
    1751   if (pci->pszLongName && pci->pszLongName != NullStr) {
    1752     psz = pci->pszLongName;
     1751  if (pci->pszLongName) {
     1752    if (pci->pszLongName != NullStr)
     1753      free(pci->pszLongName);
    17531754    pci->pszLongName = NULL;            // Catch illegal references
    1754     free(psz);
    17551755  }
    17561756
    17571757  // Bypass free if pszDisplayName points into pszFileName buffer
    17581758  // 05 Sep 08 SHL Correct pointer overlap compare logic
    1759   if (pci->pszDisplayName != pci->pszFileName &&
    1760       pci->pszDisplayName &&
    1761       pci->pszDisplayName != NullStr) {
    1762     if (!pci->pszFileName ||
    1763         pci->pszDisplayName < pci->pszFileName ||
    1764         pci->pszDisplayName >= pci->pszFileName + _msize(pci->pszFileName))
    1765     {
    1766       psz = pci->pszDisplayName;
    1767       pci->pszDisplayName = NULL;       // Catch illegal references
    1768       free(psz);
    1769     }
     1759  if (pci->pszDisplayName) {
     1760    if (pci->pszDisplayName != NullStr) {
     1761      if (!pci->pszFileName ||
     1762          pci->pszDisplayName < pci->pszFileName ||
     1763          pci->pszDisplayName >= pci->pszFileName + _msize(pci->pszFileName))
     1764      {
     1765        free(pci->pszDisplayName);
     1766      }
     1767    }
     1768    pci->pszDisplayName = NULL;         // Catch illegal references
     1769  }
     1770
     1771  if (!pci->pszFileName)
     1772    Runtime_Error(pszSrcFile, __LINE__, "FreeCnrItemData attempting free %p data twice", pci);
     1773  else {
     1774    if (pci->pszFileName != NullStr)
     1775      free(pci->pszFileName);
     1776    pci->pszFileName = NULL;            // Catch illegal references
    17701777  }
    17711778
    17721779  // 08 Sep 08 SHL Remove excess logic
    1773   if (pci->pszLongName && pci->pszLongName != NullStr) {
    1774     psz = pci->pszLongName;
     1780  if (pci->pszLongName) {
     1781    if (pci->pszLongName != NullStr)
     1782      free(pci->pszLongName);
    17751783    pci->pszLongName = NULL;            // Catch illegal references
    1776     free(psz);
    1777   }
    1778 
    1779   if (pci->pszFileName && pci->pszFileName != NullStr) {
    1780     psz = pci->pszFileName;
    1781     pci->pszFileName = NULL;            // Catch illegal references
    1782     free(psz);
    1783   }
    1784 
    1785   if (pci->pszFmtFileSize && pci->pszFmtFileSize != NullStr) {
    1786     psz = pci->pszFmtFileSize;
     1784  }
     1785
     1786  if (pci->pszFmtFileSize) {
     1787    if (pci->pszFmtFileSize != NullStr)
     1788      free(pci->pszFmtFileSize);
    17871789    pci->pszFmtFileSize = NULL;         // Catch illegal references
    1788     free(psz);
    17891790  }
    17901791}
     
    18721873          Dos_Error(MB_ENTER, apiret, HWND_DESKTOP, pszSrcFile, __LINE__,
    18731874                    "DosQueryMem failed pci %p pciLast %p", pci, pciLast);
    1874         FreeCnrItemData(pci);
     1875        FreeCnrItemData(pci);
    18751876        pciLast = pci;
    18761877        pci = (PCNRITEM)pci->rc.preccNextRecord;
Note: See TracChangeset for help on using the changeset viewer.