Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2007 Apr : CreateProcess and Memory Leak.

www.cryer.info
Managed Newsgroup Archive

CreateProcess and Memory Leak.

Subject:CreateProcess and Memory Leak.
Posted by:"Doni Devito" (do..@devito.com)
Date:Fri, 13 Apr 2007 12:34:31

Hi,
I had 2 executables written in D2006 on W2003. I had to run and wait for
termination of 2nd exe from 1st exe. For this reason Im using create process
function. I searched from the internet and found WinExecAndWait32 function
by Pat Ritchey.(thanks for pat) But I had a memory leak problem. Everytime I
executed the second exe and terminate it, it leaks around 200MB. Is there
any known issue? Here is the original WinExecAndWait32;

function WinExecAndWait32V2(FileName: string; Visibility: Integer): DWORD;
var { by Pat Ritchey }
  zAppName: array[0..512] of Char;
  zCurDir: array[0..255] of Char;
  WorkDir: string;
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
begin
  StrPCopy(zAppName, FileName);
  GetDir(0, WorkDir);
  StrPCopy(zCurDir, WorkDir);
  FillChar(StartupInfo, SizeOf(StartupInfo), #0);
  StartupInfo.cb          := SizeOf(StartupInfo);
  StartupInfo.dwFlags     := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := CmdShow;
  if not CreateProcess(nil,
    zAppName, // pointer to command line string
    nil, // pointer to process security attributes
    nil, // pointer to thread security attributes
    False, // handle inheritance flag
    CREATE_NEW_CONSOLE or // creation flags
    NORMAL_PRIORITY_CLASS,
    nil, //pointer to new environment block
    nil, // pointer to current directory name
    StartupInfo, // pointer to STARTUPINFO
    ProcessInfo) // pointer to PROCESS_INF
    then Result := WAIT_FAILED
  else
  begin
    while WaitForSingleObject(ProcessInfo.hProcess, 0) = WAIT_TIMEOUT do
    begin
      Application.ProcessMessages;
      Sleep(50);
    end;
    WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess, Result);
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread);

  end;
end;


Thanks.

Doni.
--
Open your mind
Deny ignorance
Demand truth

Replies:

www.cryer.info
Managed Newsgroup Archive