Changeset 8327 for trunk/src


Ignore:
Timestamp:
Apr 29, 2002, 7:05:30 PM (23 years ago)
Author:
sandervl
Message:

PH: memory leak fixes; extra checks for NULL pointers; CreateProcess changes for debug option; GetModuleFileName doesn't count 0 terminator

Location:
trunk/src/kernel32
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/directory.cpp

    r7935 r8327  
    1 /* $Id: directory.cpp,v 1.45 2002-02-16 18:07:20 sandervl Exp $ */
     1/* $Id: directory.cpp,v 1.46 2002-04-29 17:05:29 sandervl Exp $ */
    22
    33/*
     
    733733    LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
    734734    LPSTR extA  = HEAP_strdupWtoA( GetProcessHeap(), 0, ext );
     735 
    735736    dprintf(("SearchPathA %s %s %s", pathA, nameA, extA));
    736737    DWORD ret = DIR_SearchPath( pathA, nameA, extA, (LPSTR)full_name );
    737     HeapFree( GetProcessHeap(), 0, extA );
    738     HeapFree( GetProcessHeap(), 0, nameA );
    739     HeapFree( GetProcessHeap(), 0, pathA );
     738 
     739    if (NULL != extA)
     740      HeapFree( GetProcessHeap(), 0, extA );
     741 
     742    if (NULL != nameA)
     743      HeapFree( GetProcessHeap(), 0, nameA );
     744 
     745    if (NULL != pathA)
     746      HeapFree( GetProcessHeap(), 0, pathA );
     747 
    740748    if (!ret) return 0;
    741749
  • trunk/src/kernel32/handlenames.cpp

    r8216 r8327  
    1 /* $Id: handlenames.cpp,v 1.4 2002-04-08 11:22:47 phaller Exp $ */
     1/* $Id: handlenames.cpp,v 1.5 2002-04-29 17:05:29 sandervl Exp $ */
    22
    33/*
     
    117117HandleNames::HandleNames(void)
    118118{
     119  // Note: as handleNameMgr is a static object, the
     120  // destructor will never be called, this memory is leaked.
    119121  pSymbolicLinks = new CLinearList();
    120122}
     
    333335    rc = FALSE;
    334336  else
     337  {
    335338    // 2 - remove the link
    336339    pSymbolicLinks->removeObject(pHandleName);
     340   
     341    if (NULL != pHandleName->pszSymbolicLink )
     342      free( pHandleName->pszSymbolicLink );
     343   
     344    if (NULL != pHandleName->pszTarget )
     345      free( pHandleName->pszTarget );
     346   
     347    free( pHandleName );
     348  }
    337349 
    338350  mtxHandleNameMgr.leave();
  • trunk/src/kernel32/heap.cpp

    r7935 r8327  
    121121
    122122  BOOL fResult = curheap->Free(dwFlags, lpMem);
     123 
     124  /* 2002-04-25 PH
     125   * Apparently, Win2k does not do this. It does not touch last error,
     126   * it does not even return FALSE but just anything != TRUE.
     127   *
     128   
    123129  if (fResult == FALSE)
    124     SetLastError(ERROR_INVALID_HANDLE); /// @@@PH possibly wrong return code!
     130    SetLastError(ERROR_INVALID_HANDLE);
     131 
     132  */
    125133 
    126134  return fResult;
  • trunk/src/kernel32/initkernel32.cpp

    r8203 r8327  
    1 /* $Id: initkernel32.cpp,v 1.14 2002-04-07 15:44:10 sandervl Exp $
     1/* $Id: initkernel32.cpp,v 1.15 2002-04-29 17:05:30 sandervl Exp $
    22 *
    33 * KERNEL32 DLL entry point
     
    229229    DestroyCodeHeap();
    230230
     231    HMTerminate(); /* shutdown handlemanager */
     232
    231233#if defined(DEBUG) && defined(__IBMCPP__) && __IBMCPP__ == 300
    232234    ULONG totalmemalloc, nrcalls_malloc, nrcalls_free;
     
    238240    dprintf(("Leaked memory: %d bytes", totalmemalloc));
    239241    dprintf(("*************  KERNEL32 STATISTICS END   *****************"));
     242
     243    _dump_allocated(0);
    240244#endif
    241245
  • trunk/src/kernel32/registry.cpp

    r7846 r8327  
    1 /* $Id: registry.cpp,v 1.13 2002-02-08 15:09:30 sandervl Exp $ */
     1/* $Id: registry.cpp,v 1.14 2002-04-29 17:05:30 sandervl Exp $ */
    22
    33/*
     
    158158                        astring,
    159159                        phkResult);
    160 
    161   FreeAsciiString(astring);
     160 
     161  if (NULL != astring)
     162    FreeAsciiString(astring);
     163 
    162164  return(rc);
    163165}
     
    237239                          phkResult,
    238240                          lpdwDisposition);
    239 
    240   FreeAsciiString(astring1);
    241   FreeAsciiString(astring2);
     241 
     242  if (NULL != astring1)
     243    FreeAsciiString(astring1);
     244 
     245  if (NULL != astring2)
     246    FreeAsciiString(astring2);
     247 
    242248  return(rc);
    243249}
     
    264270  rc = O32_RegDeleteKey(ConvertKey(hKey),
    265271                        astring);
    266   FreeAsciiString(astring);
     272 
     273  if (NULL != astring)
     274    FreeAsciiString(astring);
     275 
    267276  return(rc);
    268277}
     
    326335  rc = O32_RegDeleteValue(ConvertKey(hKey),
    327336                          astring);
    328   FreeAsciiString(astring);
     337 
     338  if (NULL != astring)
     339    FreeAsciiString(astring);
     340 
    329341  return(rc);
    330342}
     
    618630  if(rc)
    619631    *arg3 = 0;
    620 
    621   FreeAsciiString(astring);
     632 
     633  if (NULL != astring)
     634    FreeAsciiString(astring);
     635 
    622636  return(rc);
    623637}
     
    683697  if(rc)
    684698    *arg5 = 0;
    685 
    686   FreeAsciiString(astring);
     699 
     700  if (NULL != astring)
     701    FreeAsciiString(astring);
     702 
    687703  return(rc);
    688704}
     
    841857    }
    842858  }
    843   FreeAsciiString(astring1);
     859 
     860  if (NULL != astring1)
     861    FreeAsciiString(astring1);
     862 
    844863  return(rc);
    845864}
     
    930949      }
    931950  }
    932   FreeAsciiString(astring);
    933   if(akeydata) {
     951 
     952  if (NULL != astring)
     953    FreeAsciiString(astring);
     954 
     955  if(akeydata)
    934956    free(akeydata);
    935   }
     957
    936958  return(rc);
    937959}
     
    10021024
    10031025  rc = RegSetValueA(hkey, astring1, dwType, astring2, cbData);
    1004 
    1005   FreeAsciiString(astring1);
    1006   FreeAsciiString(astring2);
     1026 
     1027  if (NULL != astring1)
     1028    FreeAsciiString(astring1);
     1029 
     1030  if (NULL != astring2)
     1031    FreeAsciiString(astring2);
     1032 
    10071033  return(rc);
    10081034}
     
    10911117  }
    10921118  rc = RegSetValueExA(hkey, astring, dwReserved, fdwType, lpbData, cbData);
     1119 
    10931120  if(akeydata)
    10941121    FreeAsciiString(akeydata);
    1095 
    1096   FreeAsciiString(astring);
     1122 
     1123  if (NULL != astring)
     1124    FreeAsciiString(astring);
     1125 
    10971126  return(rc);
    10981127}
  • trunk/src/kernel32/winimagebase.cpp

    r7811 r8327  
    1 /* $Id: winimagebase.cpp,v 1.34 2002-02-06 16:33:39 sandervl Exp $ */
     1/* $Id: winimagebase.cpp,v 1.35 2002-04-29 17:05:30 sandervl Exp $ */
    22
    33/*
     
    322322        *subsystem = oh.Subsystem;
    323323  }
     324 
     325  free(win32file);
    324326  DosClose(win32handle);
    325327  return ERROR_SUCCESS_W;
  • trunk/src/kernel32/wprocess.cpp

    r8015 r8327  
    1 /* $Id: wprocess.cpp,v 1.149 2002-02-26 11:11:17 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.150 2002-04-29 17:05:30 sandervl Exp $ */
    22
    33/*
     
    340340        }
    341341        threadListMutex.leave();
    342 
     342     
     343        // PH 2002-04-11
     344        // free allocated memory
     345        free( winteb->o.odin.threadinfo.pTokenGroups );
     346     
     347#ifdef DEBUG
     348        if (winteb->o.odin.arrstrCallStack != NULL)
     349          free( winteb->o.odin.arrstrCallStack );
     350#endif
     351     
    343352        //Restore our original FS selector
    344353        SetFS(orgtibsel);
     
    12031212         */
    12041213        cch = strlen(pszPeExe)+1;
     1214     
     1215        // PH 2002-04-11
     1216        // Note: intentional memory leak, pszCmdLineW will not be freed
     1217        // or allocated after process startup
    12051218        pszCmdLineA = psz = (PSZ)malloc(cch);
    12061219        if (psz == NULL)
     
    13041317    if (rc == NO_ERROR)
    13051318    {
     1319      // PH 2002-04-11
     1320      // Note: intentional memory leak, pszCmdLineW will not be freed
     1321      // or allocated after process startup
    13061322        pszCmdLineW = (WCHAR*)malloc(cch * 2);
    13071323        if (pszCmdLineW != NULL)
     
    14021418 *              terminating '\0'.
    14031419 *              On error 0 is returned. Last error is set.
     1420 *
     1421 *              2002-04-25 PH
     1422 *              Q - Do we set ERROR_BUFFER_OVERFLOW when cch > cchPath?
     1423 *              Q - Does NT really set the last error?
     1424 *              A > Win2k does not set LastError here, remains OK
     1425 *
     1426 *              While GetModuleFileName does add a trailing termination zero
     1427 *              if there is enough room, the returned number of characters
     1428 *              *MUST NOT* include the zero character!
     1429 *              (Notes R6 Installer on Win2kSP6, verified Testcase)
     1430 *
    14041431 * @param       hModule     Handle to the module you like to get the file name to.
    14051432 * @param       lpszPath    Output buffer for full path and file name.
     
    14211448 * @author      knut st. osmundsen (knut.stange.osmundsen@mynd.no)
    14221449 *              Sander van Leeuwen (sandervl@xs4all.nl)
     1450 *              Patrick Haller     (patrick.haller@innotek.de)
    14231451 * @remark      - Do we still have to call Open32?
    1424  *              - Do we set ERROR_BUFFER_OVERFLOW when cch > cchPath?
    1425  *              - Does NT really set the last error?
    14261452 */
    14271453DWORD WIN32API GetModuleFileNameA(HMODULE hModule, LPTSTR lpszPath, DWORD cchPath)
    14281454{
    14291455    Win32ImageBase *    pMod;           /* Pointer to the module object. */
    1430     DWORD               cch;            /* Length of the  */
    1431 
     1456    DWORD               cch = 0;        /* Length of the  */
     1457 
     1458    // PH 2002-04-24 Note:
     1459    // WIN2k just crashes in NTDLL if lpszPath is invalid!
    14321460    if (!VALID_PSZ(lpszPath))
    14331461    {
     
    14441472        if (pszFn)
    14451473        {
    1446             cch = strlen(pszFn) + 1;
    1447             if (cch > cchPath)
    1448                 cch = cchPath;
     1474            cch = strlen(pszFn);
     1475            if (cch >= cchPath)
     1476              cch = cchPath;
     1477            else
     1478              // if there is sufficient room for the zero termination,
     1479              // write it additionally, uncounted
     1480              lpszPath[cch] = '\0';
     1481             
    14491482            memcpy(lpszPath, pszFn, cch);
    1450             lpszPath[cch - 1] = '\0';
    14511483        }
    14521484        else
     
    14631495        //(console init only it seems...)
    14641496        cch = OSLibDosGetModuleFileName(hModule, lpszPath, cchPath);
    1465         if (cch > 0)    cch++;          /* Open32 doesn't count the terminator. */
    14661497    }
    14671498
     
    17941825
    17951826    DWORD Characteristics, SubSystem, fNEExe;
    1796     if(Win32ImageBase::isPEImage(szAppName, &Characteristics, &SubSystem, &fNEExe) == 0) {
    1797         char *lpszPE;
    1798         if(SubSystem == IMAGE_SUBSYSTEM_WINDOWS_CUI) {
    1799              lpszPE = "PEC.EXE";
    1800         }
    1801         else lpszPE = "PE.EXE";
    1802 
     1827    if(Win32ImageBase::isPEImage(szAppName, &Characteristics, &SubSystem, &fNEExe) == 0)
     1828    {
     1829      char *lpszPE;
     1830      char *lpszExecutable;
     1831      int  iNewCommandLineLength;
     1832
     1833      // calculate base length for the new command line
     1834      iNewCommandLineLength = strlen(szAppName) + strlen(lpCommandLine);
     1835     
     1836      if(SubSystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
     1837        lpszExecutable = "PEC.EXE";
     1838      else
     1839        lpszExecutable = "PE.EXE";
     1840     
     1841      lpszPE = lpszExecutable;
     1842     
     1843      // 2002-04-24 PH
     1844      // set the ODIN32.DEBUG_CHILD environment variable to start new PE processes
     1845      // under a new instance of the (IPMD) debugger.
     1846#ifdef DEBUG
     1847      CHAR debug_szPE[ 512 ];
     1848      PSZ debug_pszOS2Debugger  = getenv("ODIN32.DEBUG_CHILD");
     1849      if (NULL != debug_pszOS2Debugger)
     1850      {
     1851        // build new start command
     1852        strcpy(debug_szPE, debug_pszOS2Debugger);
     1853        strcat(debug_szPE, " ");
     1854        strcat(debug_szPE, lpszExecutable);
     1855       
     1856        // we require more space in the new command line
     1857        iNewCommandLineLength += strlen( debug_szPE );
     1858       
     1859        // only launch the specified executable (ICSDEBUG.EXE)
     1860        lpszPE = debug_szPE;
     1861        lpszExecutable = debug_pszOS2Debugger;
     1862      }
     1863#endif
     1864     
    18031865        //SvL: Allright. Before we call O32_CreateProcess, we must take care of
    18041866        //     lpCurrentDirectory ourselves. (Open32 ignores it!)
     
    18061868            char *newcmdline;
    18071869
    1808             newcmdline = (char *)malloc(strlen(lpCurrentDirectory) + strlen(szAppName) + strlen(lpCommandLine) + 32);
     1870            newcmdline = (char *)malloc(strlen(lpCurrentDirectory) + iNewCommandLineLength + 32);
    18091871            sprintf(newcmdline, "%s /OPT:[CURDIR=%s] %s %s", lpszPE, lpCurrentDirectory, szAppName, lpCommandLine);
    18101872            free(cmdline);
     
    18141876            char *newcmdline;
    18151877
    1816             newcmdline = (char *)malloc(strlen(szAppName) + strlen(lpCommandLine) + 16);
     1878            newcmdline = (char *)malloc(iNewCommandLineLength + 16);
    18171879            sprintf(newcmdline, "%s %s %s", lpszPE, szAppName, lpCommandLine);
    18181880            free(cmdline);
    18191881            cmdline = newcmdline;
    18201882        }
    1821         rc = O32_CreateProcess(lpszPE, (LPCSTR)cmdline,lpProcessAttributes,
     1883     
     1884        dprintf(("KERNEL32: CreateProcess starting [%s],[%s]",
     1885                 lpszExecutable,
     1886                 cmdline));
     1887     
     1888        rc = O32_CreateProcess(lpszExecutable, (LPCSTR)cmdline,lpProcessAttributes,
    18221889                               lpThreadAttributes, bInheritHandles, dwCreationFlags,
    18231890                               lpEnvironment, lpCurrentDirectory, lpStartupInfo,
Note: See TracChangeset for help on using the changeset viewer.