Changeset 1814 for trunk


Ignore:
Timestamp:
Jun 19, 2015, 8:37:38 PM (10 years ago)
Author:
John Small
Message:

Ticket 514: Double free error fix (which also fixes a memory leak)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/filldir.c

    r1789 r1814  
    107107  28 Jun 14 GKY Fix errors identified with CPPCheck
    108108  30 Aug 14 GKY Use saymsg2 for Suggest dialog
     109  19 Jun 15 JBS Ticket 514: Double free fix (which also fixes a memory leak)
    109110
    110111***********************************************************************/
     
    18581859  }
    18591860
    1860 #if 0 // 26 Sep 09 SHL debug dup free complaints
    1861   if (!pci->pszFileName)
    1862     Runtime_Error(pszSrcFile, __LINE__, "FreeCnrItemData attempting to free %p data twice", pci);
    1863   else {
    1864     if (pci->pszFileName != NullStr)
     1861  if (pci->pszFileName) {
     1862    if (pci->pszFileName != NullStr) {
    18651863      free(pci->pszFileName);
    1866     pci->pszFileName = NULL;            // Catch illegal references
    1867   }
    1868 #else
    1869   {
    1870     #define HIST_COUNT 50
    1871     static struct {
    1872       PCNRITEM pci;
    1873       PSZ pszFileName;
    1874     } history[HIST_COUNT];
    1875     static volatile UINT iHistNdx;
    1876     UINT i;
    1877 
    1878     if (!pci->pszFileName) {
    1879       // Looks like pci was already freed
    1880       // Try to locate original file name in history buffer
    1881       for (i = 0; i < HIST_COUNT && pci != history[i].pci; i++) { }     // Scan
    1882       if (i < HIST_COUNT) {
    1883         Runtime_Error(pszSrcFile, __LINE__, "FreeCnrItemData attempting to free %p data twice, fileName was %.260s",
    1884                       pci, history[i].pszFileName);
    1885       } else {
    1886         Runtime_Error(pszSrcFile, __LINE__, "FreeCnrItemData attempting to free %p data twice", pci);
    1887       }
    1888     }
    1889     else {
    1890       PSZ psz;
    1891       PSZ *ppsz;
    1892       // Grab a history slot
    1893       // This should work well enoungh to prevent MT/SMP conflicts
    1894       for (;;) {
    1895         i = iHistNdx;
    1896         if (++i >= HIST_COUNT)
    1897           i = 0;
    1898         if (++iHistNdx >= HIST_COUNT)
    1899           iHistNdx = 0;
    1900         if (i == iHistNdx) break;
    1901       }
    1902       ppsz = &history[iHistNdx].pszFileName;
    1903       psz = *ppsz;
    1904       if (psz)
    1905         free(psz);
    1906       if (pci->pszFileName && pci->pszFileName != NullStr)
    1907         *ppsz = strdup(pci->pszFileName);
    1908       else
    1909         *ppsz = NULL;
    1910       history[iHistNdx].pci = pci;
    1911       if (pci->pszFileName != NullStr)
    1912         free(pci->pszFileName);
    1913       pci->pszFileName = NULL;          // Catch illegal references and dup free attempts
    1914     }
    1915   }
    1916 
    1917 
    1918 #endif
    1919 
     1864    }
     1865    pci->pszFileName = NULL;            // Catch illegal references and dup free attempts
     1866  }
     1867
     1868// 26 Mar 14 JBS Twice on the longname?
    19201869  // 08 Sep 08 SHL Remove excess logic
    19211870  if (pci->pszLongName) {
     
    19941943{
    19951944  INT remaining = usCnt;
    1996   BOOL bIdlePrioritySet = FALSE;
    1997 // #define RCI_ITEMS_PER_TIMER_CHECK (10)
    1998 // 10 seems a very conservative number
    1999 //   USHORT usTimerCheckCountdown       = RCI_ITEMS_PER_TIMER_CHECK;
    20001945  PCNRITEM pci;
    20011946  ITIMER_DESC itdSleep = { 0 };         // 30 May 11 GKY
     
    20221967      while (pci) {
    20231968        FreeCnrItemData(pci);
    2024         pci = (PCNRITEM)pci->rc.preccNextRecord;
    2025         if (!pci)
    2026           break;
    20271969        if (remaining && --remaining == 0)
    20281970          break;
    2029         if (!bIdlePrioritySet /* && --usTimerCheckCountdown == 0 */) {
    2030           bIdlePrioritySet = !IdleIfNeeded(&itdSleep, 30);
    2031 //           usTimerCheckCountdown = RCI_ITEMS_PER_TIMER_CHECK;
     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;
    20321985        }
    20331986      } // while
    2034       if (bIdlePrioritySet)
    2035         priority_normal();
    2036 
    20371987      DosPostEventSem(CompactSem);
    20381988    }
    20391989  }
    2040 
    2041   // DbgMsg(pszSrcFile, __LINE__, "RemoveCnrItems %p %u %s", pci, usCnt, pci->pszFileName);
    20421990
    20431991  if (remaining != - 1) {
     
    20471995    }
    20481996  }
    2049 
    20501997  return remaining;
    20511998}
Note: See TracChangeset for help on using the changeset viewer.