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.
This commit is contained in:
Nikita Popov 2020-01-28 14:42:19 +01:00
parent 3b9e822e11
commit b0d7b126a2

View File

@ -91,7 +91,6 @@ PHP_MINIT_FUNCTION(syslog)
/* AIX doesn't have LOG_PERROR */ /* AIX doesn't have LOG_PERROR */
REGISTER_LONG_CONSTANT("LOG_PERROR", LOG_PERROR, CONST_CS | CONST_PERSISTENT); /*log to stderr*/ REGISTER_LONG_CONSTANT("LOG_PERROR", LOG_PERROR, CONST_CS | CONST_PERSISTENT); /*log to stderr*/
#endif #endif
BG(syslog_device)=NULL;
return SUCCESS; return SUCCESS;
} }
@ -108,16 +107,16 @@ PHP_RINIT_FUNCTION(syslog)
PHP_RSHUTDOWN_FUNCTION(syslog) PHP_RSHUTDOWN_FUNCTION(syslog)
{ {
closelog(); closelog();
if (BG(syslog_device)) {
efree(BG(syslog_device));
BG(syslog_device) = NULL;
}
return SUCCESS; return SUCCESS;
} }
#endif #endif
PHP_MSHUTDOWN_FUNCTION(syslog) PHP_MSHUTDOWN_FUNCTION(syslog)
{ {
if (BG(syslog_device)) {
free(BG(syslog_device));
BG(syslog_device) = NULL;
}
return SUCCESS; return SUCCESS;
} }
@ -147,9 +146,9 @@ PHP_FUNCTION(openlog)
ZEND_PARSE_PARAMETERS_END(); ZEND_PARSE_PARAMETERS_END();
if (BG(syslog_device)) { 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) { if(BG(syslog_device) == NULL) {
RETURN_FALSE; RETURN_FALSE;
} }
@ -166,8 +165,8 @@ PHP_FUNCTION(closelog)
closelog(); closelog();
if (BG(syslog_device)) { if (BG(syslog_device)) {
free(BG(syslog_device)); efree(BG(syslog_device));
BG(syslog_device)=NULL; BG(syslog_device) = NULL;
} }
RETURN_TRUE; RETURN_TRUE;
} }