Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using CreateToolhelp32Snapshot() leaks memory

0 views
Skip to first unread message

Jukka Lautanen

unread,
Oct 9, 2003, 7:10:55 AM10/9/03
to
Using the CreateToolhelp32Snapshot(TH32CS_SNAPMODULE)
function (to read the process full path) leaks memory on
some applications you are reading info from. For example
EXCEL.EXE, WINWORD.EXE, etc. The MSDN help describes that
using the CloseHandle() function in CE environment leaks
memory as this does and recommends using the
CloseToolhelp32Snapshot() which is not available in
Windows 2000 (SP4). I have implemented the reading process
as done on the example available on the MSDN help "Taking
a Snapshot and Viewing Processes". This is fatal, since we
can not ship any application that behaves like this and I
have not found a simple workaround.

Gary Chanson

unread,
Oct 9, 2003, 2:30:45 PM10/9/03
to

"Jukka Lautanen" <jukka.l...@tellabs.com> wrote in message
news:2625901c38e56$0251c1f0$a601...@phx.gbl...

I guess the only work around would be to detect what platform you're
running on and call either CloseToolhelp32Snapshot or CloseHandle as
appropriate.

--

-GJC [MS Windows SDK MVP]
-Software Consultant (Embedded systems and Real Time Controls)
-gcha...@mvps.org


-Abolish public schools


Jukka Lautanen

unread,
Oct 14, 2003, 1:35:41 AM10/14/03
to
The problem is that using the function on Windows 2000
environment causes the memory leak. On W2k only the
CloseHandle() function is available.
- Jukka Lautanen

Nikita Proskourine

unread,
Oct 19, 2003, 2:37:01 PM10/19/03
to
Try NtQuerySystemInformation (or ZwQuerySystemInformation, they point to
the same function) with SystemProcessesAndThreadsInformation information
class. It's partially documented in MSDN. You can obtain a handle to the
function with GetModuleHandle on NTDLL.DLL, followed by GetProcAddress.
If you need to define your own NtQuerySystemInformation type, note that
MSDN omits WINAPI (and in some case, NTSTATUS return code) in prototypes
listed in scarce docs of internal functions. More detailed info can be
found in Gary Nebbett's Windows NT/2000 Native API Reference.

Good luck!
NOP.

0 new messages