Overview
| Artifact ID: | b663d6cadc9c50bfcd53de9d4804583945276798 |
|---|---|
| Ticket: | 414910ffffffffffffffffffffffffffffffffff |
| Date: | 2002-08-25 04:16:49 |
| User: | davygrvy |
| Artifact Attached: | 00644f757a5d51d5987d576552f4aeecfa4604e1 |
| Filename: | patch.txt |
| Description: | suggested fix (release candidate) |
Content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83*** generic/tclEnv.c 5 Aug 2002 03:24:40 -0000 1.16 --- generic/tclEnv.c 24 Aug 2002 21:09:34 -0000 *************** *** 275,280 **** --- 275,285 ---- if ((index != -1) && (environ[index] == p)) { ReplaceString(oldValue, p); + #ifdef HAVE_PUTENV_THAT_COPIES + } else { + /* This putenv() copies instead of taking ownership */ + ckfree(p); + #endif } Tcl_MutexUnlock(&envMutex); *** unix/configure.in 22 Aug 2002 00:52:33 -0000 1.98 --- unix/configure.in 24 Aug 2002 21:09:37 -0000 *************** *** 373,378 **** --- 373,412 ---- fi #-------------------------------------------------------------------- + # Does putenv() copy or not? We need to know to avoid memory leaks. + #-------------------------------------------------------------------- + + AC_MSG_CHECKING([for a putenv() that copies the buffer]) + AC_CACHE_VAL(tcl_cv_putenv_copy, + AC_TRY_RUN([ + #include <stdlib.h> + #define OURVAR "havecopy=yes" + int main (int argc, char *argv[]) + { + char *foo, *bar; + foo = (char *)strdup(OURVAR); + putenv(foo); + strcpy((char *)(strchr(foo, '=') + 1), "no"); + bar = getenv("havecopy"); + if (!strcmp(bar, "no")) { + /* doesn't copy */ + return 0; + } else { + /* does copy */ + return 1; + } + } + ], + tcl_cv_putenv_copy=no, + tcl_cv_putenv_copy=yes, + tcl_cv_putenv_copy=no) + ) + AC_MSG_RESULT($tcl_cv_putenv_copy) + if test $tcl_cv_putenv_copy = yes; then + AC_DEFINE(HAVE_PUTENV_THAT_COPIES) + fi + + #-------------------------------------------------------------------- # Check for support of nl_langinfo function #-------------------------------------------------------------------- *** win/tclWinPort.h 1 Aug 2002 13:05:31 -0000 1.32 --- win/tclWinPort.h 24 Aug 2002 21:09:40 -0000 *************** *** 421,426 **** --- 421,434 ---- #define USE_PUTENV 1 /* + * Msvcrt's putenv() copies the string rather than takes ownership of it. + */ + + #if defined(_MSC_VER) || defined(__MINGW32__) + # define HAVE_PUTENV_THAT_COPIES 1 + #endif + + /* * The following defines wrap the system memory allocation routines for * use by tclAlloc.c. */