]> granicus.if.org Git - php/commitdiff
Make BG(syslog_device) per request
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 28 Jan 2020 13:42:19 +0000 (14:42 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 28 Jan 2020 13:44:52 +0000 (14:44 +0100)
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

index b07f6d6a51c945584fd55b2762f01081087ba621..d5a8fa6e2b41880b3b86b0c0ee790250e9e0f466 100644 (file)
@@ -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;
 }