Skip to content

Commit b0d7b12

Browse files
committed
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.
1 parent 3b9e822 commit b0d7b12

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

ext/standard/syslog.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ PHP_MINIT_FUNCTION(syslog)
9191
/* AIX doesn't have LOG_PERROR */
9292
REGISTER_LONG_CONSTANT("LOG_PERROR", LOG_PERROR, CONST_CS | CONST_PERSISTENT); /*log to stderr*/
9393
#endif
94-
BG(syslog_device)=NULL;
9594

9695
return SUCCESS;
9796
}
@@ -108,16 +107,16 @@ PHP_RINIT_FUNCTION(syslog)
108107
PHP_RSHUTDOWN_FUNCTION(syslog)
109108
{
110109
closelog();
110+
if (BG(syslog_device)) {
111+
efree(BG(syslog_device));
112+
BG(syslog_device) = NULL;
113+
}
111114
return SUCCESS;
112115
}
113116
#endif
114117

115118
PHP_MSHUTDOWN_FUNCTION(syslog)
116119
{
117-
if (BG(syslog_device)) {
118-
free(BG(syslog_device));
119-
BG(syslog_device) = NULL;
120-
}
121120
return SUCCESS;
122121
}
123122

@@ -147,9 +146,9 @@ PHP_FUNCTION(openlog)
147146
ZEND_PARSE_PARAMETERS_END();
148147

149148
if (BG(syslog_device)) {
150-
free(BG(syslog_device));
149+
efree(BG(syslog_device));
151150
}
152-
BG(syslog_device) = zend_strndup(ident, ident_len);
151+
BG(syslog_device) = estrndup(ident, ident_len);
153152
if(BG(syslog_device) == NULL) {
154153
RETURN_FALSE;
155154
}
@@ -166,8 +165,8 @@ PHP_FUNCTION(closelog)
166165

167166
closelog();
168167
if (BG(syslog_device)) {
169-
free(BG(syslog_device));
170-
BG(syslog_device)=NULL;
168+
efree(BG(syslog_device));
169+
BG(syslog_device) = NULL;
171170
}
172171
RETURN_TRUE;
173172
}

0 commit comments

Comments
 (0)