* cygheap.cc (init_cygheap::close_ctty): Avoid closing console-cttys since they

don't use archetypes and this will just result in double frees.
* dll_init.cc (dll_list::protect): Define.
(dll_list::alloc): Guard list access.
(dll_list::detach): Ditto.
* dll_init.h (dll_list::protect): Declare new muto.
(dll_list::guard): Define/declare function to guard list access.
* fhandler_termios.cc (fhandler_termios::sigflush): Avoid SEGV in pathological
condition of get_ttyp() == NULL.
This commit is contained in:
Christopher Faylor 2011-04-21 00:53:55 +00:00
parent 2f9c27131f
commit 71c17c5402
6 changed files with 62 additions and 21 deletions

View File

@ -1,3 +1,16 @@
2011-04-20 Christopher Faylor <me.cygwin2011@cgf.cx>
* cygheap.cc (init_cygheap::close_ctty): Avoid closing console-cttys
since they don't use archetypes and this will just result in double
frees.
* dll_init.cc (dll_list::protect): Define.
(dll_list::alloc): Guard list access.
(dll_list::detach): Ditto.
* dll_init.h (dll_list::protect): Declare new muto.
(dll_list::guard): Define/declare function to guard list access.
* fhandler_termios.cc (fhandler_termios::sigflush): Avoid SEGV in
pathological condition of get_ttyp() == NULL.
2011-04-20 Christopher Faylor <me.cygwin2011@cgf.cx>
* select.cc (serial_cleanup): Make sure that device_specific_pipe is

View File

@ -15,6 +15,7 @@
#include "cygerrno.h"
#include "security.h"
#include "path.h"
#include "tty.h"
#include "fhandler.h"
#include "dtable.h"
#include "cygheap.h"
@ -106,6 +107,10 @@ void
init_cygheap::close_ctty ()
{
debug_printf ("closing cygheap->ctty %p", cygheap->ctty);
/* FIXME: Support for console-as-ctty is limited due to the fact that
the console doesn't use archetypes - even though they could and should */
if (cygheap->ctty->get_ttyp ()
&& cygheap->ctty->get_ttyp ()->ntty != TTY_CONSOLE)
cygheap->ctty->close ();
cygheap->ctty = NULL;
}

View File

@ -10,6 +10,7 @@ details. */
#include "winsup.h"
#include "cygerrno.h"
#include "perprocess.h"
#include "sync.h"
#include "dll_init.h"
#include "environ.h"
#include "security.h"
@ -28,6 +29,8 @@ extern void __stdcall check_sanity_and_sync (per_process *);
dll_list dlls;
muto dll_list::protect;
static bool dll_global_dtors_recorded;
/* Run destructors for all DLLs on exit. */
@ -116,6 +119,7 @@ dll_list::alloc (HINSTANCE h, per_process *p, dll_type type)
WCHAR name[NT_MAX_PATH];
DWORD namelen = GetModuleFileNameW (h, name, sizeof (name));
guard (true);
/* Already loaded? */
dll *d = dlls[name];
if (d)
@ -146,6 +150,7 @@ dll_list::alloc (HINSTANCE h, per_process *p, dll_type type)
if (type == DLL_LOAD)
loaded_dlls++;
}
guard (false);
assert (p->envptr != NULL);
return d;
}
@ -170,8 +175,11 @@ void
dll_list::detach (void *retaddr)
{
dll *d;
if (!myself || !(d = find (retaddr)))
if (!myself)
return;
guard (true);
if ((d = find (retaddr)))
{
if (d->count <= 0)
system_printf ("WARNING: trying to detach an already detached dll ...");
if (--d->count == 0)
@ -192,6 +200,8 @@ dll_list::detach (void *retaddr)
cfree (d);
}
}
guard (false);
}
/* Initialization for all linked DLLs, called by dll_crt0_1. */
void

View File

@ -72,6 +72,7 @@ class dll_list
dll *end;
dll *hold;
dll_type hold_type;
static muto protect;
public:
dll start;
int tot;
@ -90,13 +91,22 @@ public:
break;
return hold;
}
dll *istart (dll_type t)
{
hold_type = t;
hold = &start;
return inext ();
}
void guard(bool lockit)
{
if (lockit)
protect.acquire ();
else
protect.release ();
}
friend void dll_global_dtors ();
dll_list () { protect.init ("dll_list"); }
};
extern dll_list dlls;

View File

@ -371,6 +371,9 @@ fhandler_termios::lseek (_off64_t, int)
void
fhandler_termios::sigflush ()
{
if (!(get_ttyp ()->ti.c_lflag & NOFLSH))
/* FIXME: Checking get_ttyp() for NULL is not right since it should not
be NULL while this is alive. However, we can conceivably close a
ctty while exiting and that will zero this. */
if (get_ttyp () && !(get_ttyp ()->ti.c_lflag & NOFLSH))
tcflush (TCIFLUSH);
}

View File

@ -4,7 +4,7 @@
which is intended to operate similarly to a mutex but attempts to
avoid making expensive calls to the kernel.
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009 Red Hat, Inc.
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009, 2010 Red Hat, Inc.
This file is part of Cygwin.