From b0d7b126a29a1972229ac91d6d28f5331912eddb Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 28 Jan 2020 14:42:19 +0100 Subject: [PATCH] Make BG(syslog_device) per request This is not supposed to be retained across requests. Explicitly free it at the end of a request, and use the per-request allocator. --- ext/standard/syslog.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/ext/standard/syslog.c b/ext/standard/syslog.c index b07f6d6a51c..d5a8fa6e2b4 100644 --- a/ext/standard/syslog.c +++ b/ext/standard/syslog.c @@ -91,7 +91,6 @@ PHP_MINIT_FUNCTION(syslog) /* AIX doesn't have LOG_PERROR */ REGISTER_LONG_CONSTANT("LOG_PERROR", LOG_PERROR, CONST_CS | CONST_PERSISTENT); /*log to stderr*/ #endif - BG(syslog_device)=NULL; return SUCCESS; } @@ -108,16 +107,16 @@ PHP_RINIT_FUNCTION(syslog) PHP_RSHUTDOWN_FUNCTION(syslog) { closelog(); + if (BG(syslog_device)) { + efree(BG(syslog_device)); + BG(syslog_device) = NULL; + } return SUCCESS; } #endif PHP_MSHUTDOWN_FUNCTION(syslog) { - if (BG(syslog_device)) { - free(BG(syslog_device)); - BG(syslog_device) = NULL; - } return SUCCESS; } @@ -147,9 +146,9 @@ PHP_FUNCTION(openlog) ZEND_PARSE_PARAMETERS_END(); if (BG(syslog_device)) { - free(BG(syslog_device)); + efree(BG(syslog_device)); } - BG(syslog_device) = zend_strndup(ident, ident_len); + BG(syslog_device) = estrndup(ident, ident_len); if(BG(syslog_device) == NULL) { RETURN_FALSE; } @@ -166,8 +165,8 @@ PHP_FUNCTION(closelog) closelog(); if (BG(syslog_device)) { - free(BG(syslog_device)); - BG(syslog_device)=NULL; + efree(BG(syslog_device)); + BG(syslog_device) = NULL; } RETURN_TRUE; }