- Timestamp:
- Dec 1, 2008, 12:40:08 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/dll/filldir.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/filldir.c
r1299 r1308 55 55 24 Nov 08 GKY Add StubyScanThread to treecnr scan/rescan drives all on separate threads 56 56 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 57 61 58 62 ***********************************************************************/ … … 92 96 #include "wrappers.h" // xDosFindNext 93 97 #include "init.h" // GetTidForWindow 94 #include "common.h" // IncrThreadUsage98 #include "common.h" // IncrThreadUsage 95 99 96 100 VOID StubbyScanThread(VOID * arg); … … 109 113 CHAR *FM3Tools; 110 114 CHAR *WPProgram; 111 volatile INT StubbyScanCount;115 volatile INT StubbyScanCount; 112 116 113 117 typedef struct { 114 115 118 PCNRITEM pci; 116 HWND hwndCnr; //hwnd you want the message posted to119 HWND hwndCnr; // hwnd you want the message posted to 117 120 HWND hwndDrivesList; 118 121 BOOL RamDrive; 119 120 122 } 121 123 STUBBYSCAN; … … 192 194 # endif 193 195 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) { 196 198 thab = WinInitialize(0); 197 199 if (thab) { 198 200 hmq = WinCreateMsgQueue(thab, 0); 199 201 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); 218 221 } 219 222 DecrThreadUsage(); … … 1550 1553 STUBBYSCAN *StubbyScan; 1551 1554 HWND hwndDrivesList = WinWindowFromID(WinQueryWindow(hwndParent, QW_PARENT), 1552 MAIN_DRIVELIST);1555 MAIN_DRIVELIST); 1553 1556 1554 1557 //AddDrive = TRUE; 1555 1558 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)); 1559 1562 1560 1563 while (pci && (INT)pci != -1) { 1561 1564 StubbyScan = xmallocz(sizeof(STUBBYSCAN), pszSrcFile, __LINE__); 1562 1565 if (!StubbyScan) 1563 break;1566 break; 1564 1567 StubbyScan->pci = pci; 1565 1568 StubbyScan->hwndCnr = hwndCnr; … … 1567 1570 StubbyScan->RamDrive = FALSE; 1568 1571 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)); 1572 1575 if (~pci->flags & RECFLAGS_ENV) { 1573 ULONG drvNum = toupper(*pci->pszFileName) - 'A'; // 0..251574 if (drvNum == ulCurDriveNum || drvNum >= 2) {1575 ULONG flags = driveflags[drvNum]; // Speed up1576 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 scanning1587 else1588 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 } 1603 1606 } 1604 1607 pci = pciNext; … … 1739 1742 VOID FreeCnrItemData(PCNRITEM pci) 1740 1743 { 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); 1746 1747 pci->pszSubject = NULL; // Catch illegal references 1747 free(psz);1748 1748 } 1749 1749 1750 1750 // 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); 1753 1754 pci->pszLongName = NULL; // Catch illegal references 1754 free(psz);1755 1755 } 1756 1756 1757 1757 // Bypass free if pszDisplayName points into pszFileName buffer 1758 1758 // 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 1770 1777 } 1771 1778 1772 1779 // 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); 1775 1783 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); 1787 1789 pci->pszFmtFileSize = NULL; // Catch illegal references 1788 free(psz);1789 1790 } 1790 1791 } … … 1872 1873 Dos_Error(MB_ENTER, apiret, HWND_DESKTOP, pszSrcFile, __LINE__, 1873 1874 "DosQueryMem failed pci %p pciLast %p", pci, pciLast); 1874 FreeCnrItemData(pci);1875 FreeCnrItemData(pci); 1875 1876 pciLast = pci; 1876 1877 pci = (PCNRITEM)pci->rc.preccNextRecord;
Note:
See TracChangeset
for help on using the changeset viewer.
