Mail Archives: cygwin/2006/02/05/13:17:43
Hi everybody,
For one of my software projects, I need the _kbhit function to check the
console for keyboard input. While this function is present in msvcrt.dll, it
is missing from cygwin1.dll, so I started writing this function myself (I'm
hoping to contribute it to Cygwin if it works well).
However, when writing this function it appeared that there is a memory leak
in Cygwin's select() function.
To get a _kbhit-like function, I call cygwin_select() on file descriptor 0,
which in turn calls select_stuff::test_and_set. This function calls
cygheap->fdtab.select_read (0, NULL), which calls
fhandler_console::select_read (NULL). Since the argument is NULL, this
function returns a newly allocated select_record; this pointer is saved in
the select_stuff variable sel in cygwin_select (and nowhere else, as far as I
can tell). On this variable, we call select_stuff::poll; its result is
returned by cygwin_select.
So my questions are:
1) Where is the select_record deleted? The select_stuff variable sel will be
gone after we exit cygwin_select, and with it the pointer to the
select_record we allocated in select_read.
2) To avoid this memory leak, one might consider deleting the select_record
just before returning from cygwin_select. However, this does not seem to be
the right approach. In select_stuff::poll, we call peek_console, passing a
pointer to the select_record. In peek_console, we use the read_ready flag
(presumably) to save the state of the console. But, it doesn't seem useful to
save the console state if we allocate and delete the select_record each time
we call select().
My guess is that cygwin_select should pull in a saved select_record instead
of creating a new one. But from where?
Thanks in advance,
--Michiel.
Michiel de Hoon
Center for Computational Biology and Bioinformatics
Columbia University
1150 St Nicholas Avenue
New York, NY 10032
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -