Changeset 1836 for trunk/dll/filldir.c
- Timestamp:
- Jul 15, 2015, 2:48:14 AM (10 years ago)
- File:
-
- 1 edited
-
trunk/dll/filldir.c (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/filldir.c
r1814 r1836 107 107 28 Jun 14 GKY Fix errors identified with CPPCheck 108 108 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 109 110 19 Jun 15 JBS Ticket 514: Double free fix (which also fixes a memory leak) 110 111 … … 153 154 #include "pathutil.h" // AddBackslashToPath 154 155 #include "tmrsvcs.h" // ITIMER_DESC 156 #if 0 157 #define __PMPRINTF__ 158 #include "PMPRINTF.H" 159 #endif 155 160 156 161 VOID StubbyScanThread(VOID * arg); … … 424 429 BOOL fLoadSubjectForDrive = fLoadSubject && ~flags & DRIVE_NOLOADSUBJS; 425 430 BOOL fLoadLongNameForDrive = fLoadLongnames && //~flags & DRIVE_NOLONGNAMES && 426 ~flags & DRIVE_NOLOADLONGS;431 ~flags & DRIVE_NOLOADLONGS; 427 432 if (fLoadSubjectForDrive || fLoadLongNameForDrive) { 428 433 // 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__); 430 436 if (pgealist) { 431 437 APIRET rc; … … 466 472 //DbgMsg(pszSrcFile, __LINE__, "pgealist %p cbList %u", pgealist, pgealist->cbList); 467 473 468 pfealist = xmallocz( 4096, pszSrcFile, __LINE__);474 pfealist = xmallocz(65536, pszSrcFile, __LINE__); 469 475 if (pfealist) { 470 pfealist->cbList = 4096;476 pfealist->cbList = 65536; 471 477 eaop.fpGEA2List = pgealist; 472 478 eaop.fpFEA2List = pfealist; … … 514 520 pfea = (PFEA2)((PSZ)pfea + pfea->oNextEntryOffset); 515 521 } // while 516 }522 } 517 523 free(pfealist); 518 524 } … … 688 694 pci->rc.hptrIcon = hptr; 689 695 696 690 697 // check to see if record should be visible 698 DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT); 691 699 if (dcd && (*dcd->mask.szMask || dcd->mask.antiattr || 692 700 ((dcd->mask.attrFile & 693 701 (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)))) { 697 703 if (*dcd->mask.szMask || dcd->mask.antiattr) { 698 704 if (!Filter((PMINIRECORDCORE) pci, (PVOID) & dcd->mask)) 699 pci->rc.flRecordAttr |= CRA_FILTERED;705 pci->rc.flRecordAttr |= CRA_FILTERED; 700 706 } 701 707 else if ((!(dcd->mask.attrFile & FILE_HIDDEN) && … … 710 716 } 711 717 } 718 DosReleaseMutexSem(hmtxFiltering); 712 719 713 720 return pffb->cbFile + pci->easize; … … 851 858 pci->rc.hptrIcon = hptr; 852 859 860 DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT); 853 861 if (dcd && 854 862 (*dcd->mask.szMask || dcd->mask.antiattr || … … 858 866 if (*dcd->mask.szMask || dcd->mask.antiattr) { 859 867 if (!Filter((PMINIRECORDCORE) pci, (PVOID) & dcd->mask)) 860 pci->rc.flRecordAttr |= CRA_FILTERED;868 pci->rc.flRecordAttr |= CRA_FILTERED; 861 869 } 862 870 else if ((!(dcd->mask.attrFile & FILE_HIDDEN) && … … 870 878 pci->rc.flRecordAttr |= CRA_FILTERED; 871 879 } 880 DosReleaseMutexSem(hmtxFiltering); 872 881 873 882 return pfsa4->cbFile + pci->easize; … … 968 977 pffbFile = paffbFound; 969 978 ulSelCnt = 0; 970 for (;;) {979 for (;;) { 971 980 if (!*pffbFile->achName || 972 981 (!filestoo && ~pffbFile->attrFile & FILE_DIRECTORY) || … … 989 998 if (stopflag && *stopflag) 990 999 goto Abort; 991 if (fSyncUpdates) { 1000 if (fSyncUpdates) { 1001 if (!WinIsWindow(WinQueryAnchorBlock(hwndCnr), hwndCnr)) { 1002 ok = FALSE; 1003 ullTotalBytes = 0; 1004 break; 1005 } 992 1006 pciFirst = WinSendMsg(hwndCnr, CM_ALLOCRECORD, 993 1007 MPFROMLONG(EXTRA_RECORD_BYTES), … … 1005 1019 // Finish filling pci items 1006 1020 for (x = 0; x < ulSelCnt; x++) { 1007 pffbFile = papffbSelected[x];1021 pffbFile = papffbSelected[x]; 1008 1022 ullBytes = FillInRecordFromFFB(hwndCnr, pci, pszFileSpec, 1009 1023 pffbFile, partial, dcd); … … 1039 1053 if (ok) { 1040 1054 ullReturnBytes += ullTotalBytes; 1041 ulReturnFiles += ulSelCnt; 1055 ulReturnFiles += ulSelCnt; 1056 DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT); 1042 1057 if (dcd) { 1043 1058 dcd->totalfiles += ulSelCnt; 1044 1059 dcd->ullTotalBytes += ullTotalBytes; 1045 } 1060 } 1061 DosReleaseMutexSem(hmtxFiltering); 1046 1062 } 1047 1063 } // if sync updates … … 1098 1114 ULONG ulRecsToInsert; 1099 1115 1100 if (pci ==NULL) { 1116 if (pci ==NULL) { 1117 if (!WinIsWindow(WinQueryAnchorBlock(hwndCnr), hwndCnr)) { 1118 ok = FALSE; 1119 ullTotalBytes = 0; 1120 break; 1121 } 1101 1122 ulRecsToInsert = cAffbTotal - x < USHRT_MAX ? cAffbTotal - x : USHRT_MAX; 1102 1123 pciFirst = WinSendMsg(hwndCnr, CM_ALLOCRECORD, 1103 1124 MPFROMLONG(EXTRA_RECORD_BYTES), MPFROMLONG(ulRecsToInsert)); 1104 1125 1105 if (!pciFirst) { 1126 if (!pciFirst) { 1127 //ERRORID erridErrorCode = WinGetLastError(WinQueryAnchorBlock(hwndCnr)); 1128 //PmpfF(("Allocation failed %i", erridErrorCode)); 1106 1129 Win_Error(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__, 1107 1130 GetPString(IDS_CMALLOCRECERRTEXT)); … … 1118 1141 pci = pciFirst; 1119 1142 } 1120 }1143 } 1121 1144 ullBytes = FillInRecordFromFFB(hwndCnr, pci, pszFileSpec, 1122 1145 pffbFile, partial, dcd); 1123 1146 pci = (PCNRITEM) pci->rc.preccNextRecord; 1124 1147 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); 1126 1150 if (dcd) { 1127 1151 dcd->totalfiles = x; 1128 1152 dcd->ullTotalBytes = ullTotalBytes; 1129 } 1153 } 1154 DosReleaseMutexSem(hmtxFiltering); 1130 1155 // Can not use offset since we have merged lists - this should be equivalent 1131 1156 pffbFile = (PFILEFINDBUF4L)((PBYTE)pffbFile + sizeof(FILEFINDBUF4L)); 1132 1157 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++) { 1135 1160 ullBytes = FillInRecordFromFFB(hwndCnr, pci, pszFileSpec, 1136 1161 pffbFile, partial, dcd); 1137 1162 pci = (PCNRITEM) pci->rc.preccNextRecord; 1138 ullTotalBytes += ullBytes; 1163 ullTotalBytes += ullBytes; 1164 DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT); 1139 1165 if (dcd) { 1140 1166 dcd->totalfiles = x; 1141 1167 dcd->ullTotalBytes = ullTotalBytes; 1142 } 1143 pffbFile = (PFILEFINDBUF4L)((PBYTE)pffbFile + sizeof(FILEFINDBUF4L)); 1168 } 1169 DosReleaseMutexSem(hmtxFiltering); 1170 pffbFile = (PFILEFINDBUF4L)((PBYTE)pffbFile + sizeof(FILEFINDBUF4L)); 1144 1171 if (pci == NULL) { 1145 1172 priority_normal(); … … 1832 1859 VOID FreeCnrItemData(PCNRITEM pci) 1833 1860 { 1861 1834 1862 if (pci->pszSubject) { 1835 1863 if (pci->pszSubject != NullStr) … … 1837 1865 pci->pszSubject = NULL; // Catch illegal references 1838 1866 } 1839 1867 1840 1868 // 08 Sep 08 SHL Remove excess logic 1841 1869 if (pci->pszLongName) { … … 1844 1872 pci->pszLongName = NULL; // Catch illegal references 1845 1873 } 1846 1874 1847 1875 // Bypass free if pszDisplayName points into pszFileName buffer 1848 1876 // 05 Sep 08 SHL Correct pointer overlap compare logic … … 1853 1881 pci->pszDisplayName >= pci->pszFileName + _msize(pci->pszFileName)) 1854 1882 { 1855 free(pci->pszDisplayName);1883 free(pci->pszDisplayName); 1856 1884 } 1857 1885 } … … 1859 1887 } 1860 1888 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) 1863 1894 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 1869 1949 // 08 Sep 08 SHL Remove excess logic 1870 1950 if (pci->pszLongName) { … … 1943 2023 { 1944 2024 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; 1945 2029 PCNRITEM pci; 1946 2030 ITIMER_DESC itdSleep = { 0 }; // 30 May 11 GKY … … 1966 2050 InitITimer(&itdSleep, 500); 1967 2051 while (pci) { 1968 FreeCnrItemData(pci); 2052 FreeCnrItemData(pci); 2053 pci = (PCNRITEM)pci->rc.preccNextRecord; 2054 if (!pci) 2055 break; 1969 2056 if (remaining && --remaining == 0) 1970 2057 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; 1985 2061 } 1986 2062 } // while 2063 if (bIdlePrioritySet) 2064 priority_normal(); 2065 1987 2066 DosPostEventSem(CompactSem); 1988 2067 } 1989 2068 } 2069 2070 // DbgMsg(pszSrcFile, __LINE__, "RemoveCnrItems %p %u %s", pci, usCnt, pci->pszFileName); 1990 2071 1991 2072 if (remaining != - 1) { … … 1995 2076 } 1996 2077 } 2078 1997 2079 return remaining; 1998 2080 }
Note:
See TracChangeset
for help on using the changeset viewer.
