@@ -29,10 +29,12 @@ static void php_stream_error_entry_dtor(void *error)
2929{
3030 php_stream_error_entry * entry = * (php_stream_error_entry * * ) error ;
3131 zend_string_release (entry -> message );
32- efree (entry -> wrapper_name );
33- efree (entry -> docref );
32+ pefree (entry -> wrapper_name , entry -> persistent );
33+ pefree (entry -> docref , entry -> persistent );
34+ // param is not currently supported for streams so cannot be persistent
35+ ZEND_ASSERT (!entry -> persistent || entry -> param == NULL );
3436 efree (entry -> param );
35- efree (entry );
37+ pefree (entry , entry -> persistent );
3638}
3739
3840static void php_stream_error_list_dtor (zval * item )
@@ -215,18 +217,23 @@ static void php_stream_process_error(php_stream_context *context, const char *wr
215217/* Helper to create error entry */
216218static php_stream_error_entry * php_stream_create_error_entry (zend_string * message , int code ,
217219 const char * wrapper_name , const char * docref , char * param , int severity ,
218- bool terminal )
220+ bool terminal , bool persistent )
219221{
220- php_stream_error_entry * entry = emalloc (sizeof (php_stream_error_entry ));
222+ if (persistent ) {
223+ message = zend_string_dup (message , true);
224+ } else {
225+ zend_string_addref (message );
226+ }
227+
228+ php_stream_error_entry * entry = pemalloc (sizeof (php_stream_error_entry ), persistent );
221229 entry -> message = message ;
222230 entry -> code = code ;
223- entry -> wrapper_name = wrapper_name ? estrdup (wrapper_name ) : NULL ;
224- entry -> docref = docref ? estrdup (docref ) : NULL ;
231+ entry -> wrapper_name = wrapper_name ? pestrdup (wrapper_name , persistent ) : NULL ;
232+ entry -> docref = docref ? pestrdup (docref , persistent ) : NULL ;
225233 entry -> param = param ;
226234 entry -> severity = severity ;
227235 entry -> terminal = terminal ;
228-
229- zend_string_addref (message );
236+ entry -> persistent = persistent ;
230237
231238 return entry ;
232239}
@@ -243,17 +250,16 @@ static void php_stream_store_error_common(php_stream_context *context, php_strea
243250 efree (param );
244251 return ;
245252 }
246- php_stream_error_entry * entry = php_stream_create_error_entry (
247- message , code , wrapper_name , docref , param , severity , terminal );
248253
249254 zend_llist * list ;
250-
255+ bool persistent = false;
251256 if (stream ) {
257+ persistent = stream -> is_persistent ;
252258 /* Store in stream's error list */
253259 if (!stream -> error_list ) {
254- stream -> error_list = emalloc (sizeof (zend_llist ));
260+ stream -> error_list = pemalloc (sizeof (zend_llist ), persistent );
255261 zend_llist_init (stream -> error_list , sizeof (php_stream_error_entry * ),
256- php_stream_error_entry_dtor , 0 );
262+ php_stream_error_entry_dtor , persistent );
257263 }
258264 list = stream -> error_list ;
259265 } else {
@@ -276,6 +282,9 @@ static void php_stream_store_error_common(php_stream_context *context, php_strea
276282 }
277283 }
278284
285+ php_stream_error_entry * entry = php_stream_create_error_entry (
286+ message , code , wrapper_name , docref , param , severity , terminal , persistent );
287+
279288 zend_llist_add_element (list , & entry );
280289}
281290
@@ -368,7 +377,7 @@ static void php_stream_wrapper_log_store_error(zend_string *message, int code,
368377{
369378 char * param_copy = param ? estrdup (param ): NULL ;
370379 php_stream_error_entry * entry = php_stream_create_error_entry (
371- message , code , wrapper_name , NULL , param_copy , severity , terminal );
380+ message , code , wrapper_name , NULL , param_copy , severity , terminal , false );
372381
373382 if (!FG (wrapper_logged_errors )) {
374383 ALLOC_HASHTABLE (FG (wrapper_logged_errors ));
0 commit comments