* 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

@@ -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,27 +175,32 @@ void
dll_list::detach (void *retaddr)
{
dll *d;
if (!myself || !(d = find (retaddr)))
if (!myself)
return;
if (d->count <= 0)
system_printf ("WARNING: trying to detach an already detached dll ...");
if (--d->count == 0)
guard (true);
if ((d = find (retaddr)))
{
/* Ensure our exception handler is enabled for destructors */
exception protect;
/* Call finalize function if we are not already exiting */
if (!exit_state)
__cxa_finalize (d);
d->run_dtors ();
d->prev->next = d->next;
if (d->next)
d->next->prev = d->prev;
if (d->type == DLL_LOAD)
loaded_dlls--;
if (end == d)
end = d->prev;
cfree (d);
if (d->count <= 0)
system_printf ("WARNING: trying to detach an already detached dll ...");
if (--d->count == 0)
{
/* Ensure our exception handler is enabled for destructors */
exception protect;
/* Call finalize function if we are not already exiting */
if (!exit_state)
__cxa_finalize (d);
d->run_dtors ();
d->prev->next = d->next;
if (d->next)
d->next->prev = d->prev;
if (d->type == DLL_LOAD)
loaded_dlls--;
if (end == d)
end = d->prev;
cfree (d);
}
}
guard (false);
}
/* Initialization for all linked DLLs, called by dll_crt0_1. */