From db49677f523a0ba720d90047aded7b4b8ed5b916 Mon Sep 17 00:00:00 2001 From: Michael Maroszek Date: Thu, 7 Jul 2016 14:24:05 +0200 Subject: [PATCH 1/2] fix bug #72024 (microtime() leaks memory) --- ext/standard/string.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index 39413c8211707..1ecbdb97ce01f 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -195,7 +195,6 @@ static char *php_hex2bin(const unsigned char *old, const size_t oldlen, size_t * * glibc's localeconv is not reentrant, so lets make it so ... sorta */ PHPAPI struct lconv *localeconv_r(struct lconv *out) { - struct lconv *res; # ifdef ZTS tsrm_mutex_lock( locale_mutex ); @@ -206,16 +205,14 @@ PHPAPI struct lconv *localeconv_r(struct lconv *out) /* Even with the enabled per thread locale, localeconv won't check any locale change in the master thread. */ _locale_t cur = _get_current_locale(); - - res = cur->locinfo->lconv; + *out = *cur->locinfo->lconv; + _free_locale(cur); } #else /* localeconv doesn't return an error condition */ - res = localeconv(); + *out = *localeconv(); #endif - *out = *res; - # ifdef ZTS tsrm_mutex_unlock( locale_mutex ); # endif From 577ac3331da6cb52ce9e5ec2286d06edc7d716e9 Mon Sep 17 00:00:00 2001 From: Michael Maroszek Date: Fri, 8 Jul 2016 11:46:43 +0200 Subject: [PATCH 2/2] Backported fixed bug #71144 (Sementation fault when using cURL with ZTS) --- ext/curl/interface.c | 9 +++++++++ ext/curl/tests/bug71144.phpt | 13 +++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 ext/curl/tests/bug71144.phpt diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 19d8bb02b5899..4846cea894f8c 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -1925,7 +1925,9 @@ static void _php_curl_set_default_options(php_curl *ch) curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch); curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, curl_write_header); curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch); +#if !defined(ZTS) curl_easy_setopt(ch->cp, CURLOPT_DNS_USE_GLOBAL_CACHE, 1); +#endif curl_easy_setopt(ch->cp, CURLOPT_DNS_CACHE_TIMEOUT, 120); curl_easy_setopt(ch->cp, CURLOPT_MAXREDIRS, 20); /* prevent infinite redirects */ @@ -2263,6 +2265,13 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue TSRMLS_DC) return 1; } #endif + +#if defined(ZTS) + if (option == CURLOPT_DNS_USE_GLOBAL_CACHE) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "CURLOPT_DNS_USE_GLOBAL_CACHE cannot be activated when thread safety is enabled"); + return 1; + } +#endif error = curl_easy_setopt(ch->cp, option, Z_LVAL_PP(zvalue)); break; case CURLOPT_SAFE_UPLOAD: diff --git a/ext/curl/tests/bug71144.phpt b/ext/curl/tests/bug71144.phpt new file mode 100644 index 0000000000000..059cd63651f89 --- /dev/null +++ b/ext/curl/tests/bug71144.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug #71144 (Sementation fault when using cURL with ZTS) +--SKIPIF-- + + +--FILE-- + +--EXPECTF-- +Warning: curl_setopt(): CURLOPT_DNS_USE_GLOBAL_CACHE cannot be activated when thread safety is enabled in %sbug71144.php on line %d +bool(false)