Changeset 1795 for trunk/dll/misc.c


Ignore:
Timestamp:
Sep 7, 2014, 7:35:35 PM (11 years ago)
Author:
Gregg Young
Message:

Changes to free original memory on reallocate failure. I wonder if by reallocating and then redirecting the pszFileName etc to point to the reallocated memory as opposed to directly reallocating it will have any effect on the double free issue?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/misc.c

    r1792 r1795  
    874874              xfree(psz, pszSrcFile, __LINE__);
    875875            }
    876             else
    877               pci->pszSubject = xrealloc(pci->pszSubject, retlen + 1, pszSrcFile, __LINE__);
     876            else {
     877              psz = xrealloc(pci->pszSubject, retlen + 1, pszSrcFile, __LINE__);
     878              if (psz)
     879                pci->pszSubject = psz;
     880              else {
     881                free(pci->pszSubject);
     882                pci->pszSubject = NullStr;
     883                return FALSE; // out of memory
     884              }
     885            }
    878886          }
    879887          else {
     
    934942              xfree(psz, pszSrcFile, __LINE__);
    935943            }
    936             else
    937               pci->pszLongName = xrealloc(pci->pszLongName, retlen + 1, pszSrcFile, __LINE__);
     944            else {
     945              psz = xrealloc(pci->pszLongName, retlen + 1, pszSrcFile, __LINE__);
     946              if (psz)
     947                pci->pszLongName = psz;
     948              else {
     949                free(pci->pszLongName);
     950                pci->pszLongName = NullStr;
     951                return FALSE; // out of memory
     952              }
     953            }
    938954          }
    939955          else {
     
    944960          return (MRESULT) WriteLongName(pci->pszFileName, longname);
    945961        }
    946         else {
     962        else {
     963          PSZ psz;
     964
    947965          WinQueryWindowText(hwndMLE, sizeof(szData), szData);
    948966          if (strchr(szData, '?') ||
     
    964982                                 sizeof(szData)))
    965983            {
    966               pci->pszFileName = xrealloc(pci->pszFileName, sizeof(szData), pszSrcFile, __LINE__);
     984              psz = xrealloc(pci->pszFileName, sizeof(szData), pszSrcFile, __LINE__);
     985              if (psz)
     986                pci->pszFileName = psz;
     987              else {
     988                free(pci->pszFileName);
     989                pci->pszFileName = NullStr;
     990                return FALSE; // out of memory
     991              }
    967992              strcpy(szData, pci->pszFileName);
    968993            }
Note: See TracChangeset for help on using the changeset viewer.