From ebd645e7e65aa46fc5e95fda0b47590f4331fc17 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Wed, 3 Oct 2001 03:49:26 +0000 Subject: * cygheap.cc (cfree): Remove malloc debugging probe. * dlmalloc.c (errprint): Remove abort() call which causes interesting error message printing to abort prematurely. * environ.cc: Sprinkle MALLOC_CHECKs liberally throughout. (_addenv): Allocate two empty elements at end of environ to (apparently) work around problems with some buggy applications. (winenv): Avoid calling alloca if no forced environment variable is present. * exceptions.cc (open_stackdumpfile): Don't print "Dumping stack trace to..." when running in a cygwin environment (i.e., the parent is a cygwin process). * dtable.cc (dtable::init_std_file_from_handle): Move device type detection code from build_fhandler here since it is only used by this function. (dtable::build_fhandler_from_name): New method. Renamed from dtable::build_fhandler. (dtable::build_fhandler): Use build_fhandler_from_name. (cygwin_attach_handle_to_fd): Ditto. * syscalls.cc (_open): Ditto. (stat_worker): Ditto. * dtable.h (dtable::build_fhandler_from_name): Rename declaration from dtable::build_fhandler. --- winsup/cygwin/environ.cc | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'winsup/cygwin/environ.cc') diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc index c1529e704..e311e4b56 100644 --- a/winsup/cygwin/environ.cc +++ b/winsup/cygwin/environ.cc @@ -76,6 +76,7 @@ static unsigned char conv_start_chars[256] = {0}; void win_env::add_cache (const char *in_posix, const char *in_native) { + MALLOC_CHECK; posix = (char *) realloc (posix, strlen (in_posix) + 1); strcpy (posix, in_posix); if (in_native) @@ -90,6 +91,7 @@ win_env::add_cache (const char *in_posix, const char *in_native) (void) strcpy (native, name); towin32 (in_posix, native + namelen); } + MALLOC_CHECK; debug_printf ("posix %s", posix); debug_printf ("native %s", native); } @@ -145,6 +147,7 @@ posify (char **here, const char *value) debug_printf ("env var converted to %s", outenv); *here = outenv; free (src); + MALLOC_CHECK; } /* @@ -177,6 +180,7 @@ my_findenv (const char *name, int *offset) *offset = p - cur_environ (); return (char *) (++c); } + MALLOC_CHECK; return NULL; } @@ -231,12 +235,12 @@ _addenv (const char *name, const char *value, int overwrite) else { /* Create new slot. */ int sz = envsize (cur_environ ()); - int allocsz = sz + sizeof (char *); + int allocsz = sz + (2 * sizeof (char *)); offset = (sz - 1) / sizeof (char *); /* Allocate space for additional element plus terminating NULL. */ - if (__cygwin_environ == lastenviron) + if (cur_environ () == lastenviron) lastenviron = __cygwin_environ = (char **) realloc (cur_environ (), allocsz); else if ((lastenviron = (char **) malloc (allocsz)) != NULL) @@ -248,7 +252,7 @@ _addenv (const char *name, const char *value, int overwrite) #ifdef DEBUGGING try_to_debug (); #endif - return -1; /* Oops. No more memory. */ + return -1; /* Oops. No more memory. */ } __cygwin_environ[offset + 1] = NULL; /* NULL terminate. */ @@ -282,6 +286,7 @@ _addenv (const char *name, const char *value, int overwrite) if ((spenv = getwinenv (envhere))) spenv->add_cache (value); + MALLOC_CHECK; return 0; } @@ -612,13 +617,11 @@ parse_options (char *buf) static void __stdcall regopt (const char *name) { - MALLOC_CHECK; /* FIXME: should not be under mount */ reg_key r (KEY_READ, CYGWIN_INFO_PROGRAM_OPTIONS_NAME, NULL); char buf[MAX_PATH]; char lname[strlen(name) + 1]; strlwr (strcpy (lname, name)); - MALLOC_CHECK; if (r.get_string (lname, buf, sizeof (buf) - 1, "") == ERROR_SUCCESS) parse_options (buf); else @@ -810,18 +813,21 @@ winenv (const char * const *envp, int keep_posix) for (int i = 0; forced_winenv_vars[i]; i++) if (!saw_forced_winenv[i]) { - int namelen = strlen (forced_winenv_vars[i]) + 1; - int vallen = GetEnvironmentVariable (forced_winenv_vars[i], dum, 0) + 1; - p = (char *) alloca (namelen + vallen); - strcpy (p, forced_winenv_vars[i]); - strcat (p, "="); - if (!GetEnvironmentVariable (forced_winenv_vars[i], p + namelen, - vallen + 1)) - debug_printf ("warning: %s not present in environment", *srcp); - else + int vallen = GetEnvironmentVariable (forced_winenv_vars[i], dum, 0); + if (vallen > 0) { - *dstp++ = p; - tl += strlen (p) + 1; + int namelen = strlen (forced_winenv_vars[i]) + 1; + p = (char *) alloca (namelen + ++vallen); + strcpy (p, forced_winenv_vars[i]); + strcat (p, "="); + if (!GetEnvironmentVariable (forced_winenv_vars[i], p + namelen, + vallen)) + debug_printf ("warning: %s not present in environment", *srcp); + else + { + *dstp++ = p; + tl += strlen (p) + 1; + } } } -- cgit v1.2.3