From: qfel on
> By the way, you're NOT supposed to pass a constant string to
> CreateProcess.
Applies only to Unicode version.

From: chpichaud on
The 2nd parameter or CreateProcess is [in, out] so use a local
variable.

<<
lpCommandLine
[in, out] Pointer to a null-terminated string that specifies the
command line to execute. The maximum length of this string is 32K
characters.
Windows 2000: The maximum length of this string is MAX_PATH
characters.
The Unicode version of this function, CreateProcessW, will fail if this
parameter is a const string.

The lpCommandLine parameter can be NULL. In that case, the function
uses the string pointed to by lpApplicationName as the command line.

>>

Else:
put your string into a local TCHAR[].
Remove the std::cout function.
try it in ANSI and Unicode.

Christophe Pichaud

From: Luc Kumps on
lugeon wrote:
> You are right...
>
> But I write here the simplest code I could wrote. My leak is still
> present if I replace my constant string by a LPTSTR.
>
> Am I the only one to get a leak with this code, or has anybody the
> same trouble?

I added

#include <iostream>
#include <windows.h>
using namespace std;

in front of your code, and compiled with "cl -GX tmp.cpp"

Then I made a TestFile.exe which does Sleep(200) and ran the program. Task
Manager says VM size=156K. It stays that way forever...

Luc K


From: Luc Kumps on
Luc Kumps wrote:
> lugeon wrote:
>> You are right...
>>
>> But I write here the simplest code I could wrote. My leak is still
>> present if I replace my constant string by a LPTSTR.
>>
>> Am I the only one to get a leak with this code, or has anybody the
>> same trouble?
>
> I added
>
> #include <iostream>
> #include <windows.h>
> using namespace std;
>
> in front of your code, and compiled with "cl -GX tmp.cpp"
>
> Then I made a TestFile.exe which does Sleep(200) and ran the program.
> Task Manager says VM size=156K. It stays that way forever...

WAIT! I made a mistake!
VM size *does* increase, just like you said it does!

Luc K


From: Luc Kumps on
lugeon wrote:
> I get a 388bytes memory leak each time I call the CreateProcess()
> function. Here is my following code:

I was able to reproduce this problem.
To my surprise, CreateProcess keeps eating memory!!!

I also found a simple workaround, but I would *really* like to get an
explanation for this!

Simply add
#include <objbase.h>
to your #include statements and at the start of your main program add one
line
HRESULT hr = CoInitializeEx(NULL,COINIT_MULTITHREADED);
(or any other call that initializes the COM library).

Compile with _WIN32_DCOM defined and your leak is gone. Tested on Win2000
and WinXp.
Just don't ask me why!!!

Even simpler workaround: simply call ::SysAllocString(L"abc"); at the start
of your program...

BTW, I tried to use CreateProcessW, it has the same 'feature'!

Luc K


First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: LowLevelHooksTimeout?
Next: Hook Windows Events