Re: Dealing with HANDLEs



I found the issue with the leaks. Kinda strange... maybe just since I
don't understand it:

On every new process event this program creates a new Process object and
passes it for processing. First thing before processing I pass a pointer of
this object to a function that looks at the <list> of processes the service
looked at already and if the PID is found there it deletes the passed
pointer and assigns the pointer from the <list> to it.

The declaration was:

void GetPointerOfProcessFromList( CProcess* pProcess)


This worked in debug. But in release it didn't seem to return the pointer
correctly, and that's why it called OpenProcess on the object again. When
I changed the function to return the pointer it worked:

CProcess* GetPointerOfProcessFromList( CProcess* pProcess)


Strange, I thought if I pass a pointer, it's like by ref, I can change its
address and it changes the passed object, not a copy of it. Also, it worked
in debug. I know it's getting out of the scope of this thread... but just
wanted to mention what the issue was.

Thank you all for the support!


"Ben Menashe" <benm5678@xxxxxxxxx> wrote in message
news:cO1ch.38$lg3.37@xxxxxxxxxxxxxxx
Ok, so last tips i'm asking for.... suddenly the release ver of my code
started leaking handles, and i'm not sure what caused it. Everytime i've
seen this before, I was able to reproduce in debug mode and slowly find
the root. But this time, in debug it works fine. And this is not a small
leak... every 10 sec. it leaks about 70 handles (the # of running procs)
since it does a scan on all those processes using that class.

But I'm opening the handle only once, and closing on destructor now....
AND, it works in debug. So I'm confused. Is there any good techniques
for debugging this ?

Thanks !!


"Le Chaud Lapin" <jaibuduvin@xxxxxxxxx> wrote in message
news:1165002981.368288.312810@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

adebaene@xxxxxxxxxxxxxxxx wrote:
I agree, the problem is not a technical one : It is perfectly ok to use
DuplicateHandle as long as you play along the rules, but that's not the
point...
The problem I noticed is about object model : It's just rather
unnatural that a "Process" class is copyable. If there were such a
class, I would expect than, when an instance is duplicated, a new
process is launched (forked) on the system, and I doublt that is what
the OP wants
"Process" is just an identity object, who shouldn't be copyable for
semantic reasons ; as Jake as said, if you need to put them in an STL
collection, use (smart)pointers.

Salut,

I have to agree with you on the principle of natural conception. I did
look back and see that he is working with processes.

The technique Jake and I were proposing works for other kernel-mode
objects like mutexes, semaphore, etc. As for processes (and thread),
you're correct - there are some semantic issues that cannot be
overlooked. In particular, once you start controlling the underlying
mechanism (pausing, etc.) then there are other issues.

But...if you are working with other synchronization objects like
events, etc... then the C++ copy/assignment framework using
DuplicateHandle works well.

-Le Chaud Lapin-





.



Relevant Pages

  • Re: Release version crashes - again
    ... DWORD *pointer = NULL; ... are not usually equal in retail, but they usually are in debug. ... but my code is crashing in the CONSTRUCTOR area (long ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: checking if pointer is NULL allowed?
    ... If it has been freed and causes the debug to crash, ... macro used in debugging routines that can take a pointer and return the ... There are routines that allocate a chunk of memory to store a number ...
    (comp.lang.c)
  • Re: checking if pointer is NULL allowed?
    ... If it has been freed and causes the debug to crash, ... generally not interested in the pointer once it has been freedCare to show how you would implement this? ... There are routines that allocate a chunk of memory to store a number ...
    (comp.lang.c)
  • When the based variables basing pointer is pointer based...
    ... I have a data structure which is pointer based (the data is in the ... The user space contains pointers to linked list entries in the heap. ... I threw it into debug, ...
    (comp.sys.ibm.as400.misc)
  • Re: Crash observed with object on stack but not on heap
    ... observing very strange behavior related to crash due to this pointer ... we are running our servers on 24*7 env and facing crash sometimes. ... so when it tries to use any data member of s class inside function, ...
    (comp.os.linux.development.apps)