File tree Expand file tree Collapse file tree 5 files changed +63
-0
lines changed Expand file tree Collapse file tree 5 files changed +63
-0
lines changed Original file line number Diff line number Diff line change @@ -688,3 +688,28 @@ const char* nr_php_mysqli_strip_persistent_prefix(const char* host) {
688
688
689
689
return host ;
690
690
}
691
+
692
+ void nr_mysqli_rshutdown () {
693
+ /*
694
+ * This frees mysqli metadata stored in the transaction.
695
+ *
696
+ * `mysqli_queries` contains duplicates of zvals. If
697
+ * `nr_php_txn_end` is called from the post-deactivate callback, request
698
+ * shutdown functions have already been called; and the Zend VM has already
699
+ * forcefully freed all dangling zvals that are not referenced by the global
700
+ * scope (regardless of their reference count), thus leaving the zvals stored
701
+ * in the mysqli_queries metadata in an "undefined" state. Consequently,
702
+ * freeing the zvals in `nr_php_txn_end` at this stage can result in undefined
703
+ * behavior.
704
+ *
705
+ * Calling this function during the RSHUTDOWN phase ensures that the zvals in
706
+ * `mysqli_queries` are cleaned up before Zend winds down the VM and
707
+ * forcefully frees zvals.
708
+ *
709
+ * If `nr_php_txn_end` is called outside the post-deactivate callback,
710
+ * it frees `mysqli_queries` by itself.
711
+ */
712
+ if (nrlikely (NRPRG (txn ))) {
713
+ nr_hashmap_destroy (& NRTXNGLOBAL (mysqli_queries ));
714
+ }
715
+ }
Original file line number Diff line number Diff line change @@ -163,4 +163,10 @@ extern nr_datastore_instance_t* nr_php_mysqli_retrieve_datastore_instance(
163
163
extern void nr_php_mysqli_remove_datastore_instance (
164
164
const zval * mysqli_obj TSRMLS_DC );
165
165
166
+ /*
167
+ * Purpose : Frees reference incremented, transaction global zvals
168
+ * that must be cleaned up prior to postdeactivate
169
+ */
170
+ extern void nr_mysqli_rshutdown ();
171
+
166
172
#endif /* PHP_MYSQLI_HDR */
Original file line number Diff line number Diff line change @@ -642,3 +642,28 @@ zval* nr_php_pdo_disable_persistence(const zval* options TSRMLS_DC) {
642
642
nr_php_zval_free (& persistent );
643
643
return result ;
644
644
}
645
+
646
+ void nr_pdo_rshutdown () {
647
+ /*
648
+ * This frees pdo metadata stored in the transaction.
649
+ *
650
+ * `pdo_link_options` contains duplicates of zvals. If
651
+ * `nr_php_txn_end` is called from the post-deactivate callback, request
652
+ * shutdown functions have already been called; and the Zend VM has already
653
+ * forcefully freed all dangling zvals that are not referenced by the global
654
+ * scope (regardless of their reference count), thus leaving the zvals stored
655
+ * in the pdo_link_options metadata in an "undefined" state. Consequently,
656
+ * freeing the zvals in `nr_php_txn_end` at this stage can result in undefined
657
+ * behavior.
658
+ *
659
+ * Calling this function during the RSHUTDOWN phase ensures that the zvals in
660
+ * `pdo_link_options` are cleaned up before Zend winds down the VM and
661
+ * forcefully frees zvals.
662
+ *
663
+ * If `nr_php_txn_end` is called outside the post-deactivate callback,
664
+ * it frees `pdo_link_options` by itself.
665
+ */
666
+ if (nrlikely (NRPRG (txn ))) {
667
+ nr_hashmap_destroy (& NRTXNGLOBAL (pdo_link_options ));
668
+ }
669
+ }
Original file line number Diff line number Diff line change @@ -161,4 +161,9 @@ extern nr_status_t nr_php_pdo_parse_data_source(
161
161
extern void nr_php_pdo_free_data_sources (struct pdo_data_src_parser * parsed ,
162
162
size_t nparams );
163
163
164
+ /*
165
+ * Purpose : Frees reference incremented, transaction global zvals
166
+ * that must be cleaned up prior to postdeactivate
167
+ */
168
+ extern void nr_pdo_rshutdown ();
164
169
#endif
Original file line number Diff line number Diff line change @@ -49,6 +49,8 @@ PHP_RSHUTDOWN_FUNCTION(newrelic) {
49
49
50
50
nr_guzzle4_rshutdown (TSRMLS_C );
51
51
nr_curl_rshutdown (TSRMLS_C );
52
+ nr_pdo_rshutdown ();
53
+ nr_mysqli_rshutdown ();
52
54
53
55
nrl_verbosedebug (NRL_INIT , "RSHUTDOWN processing done" );
54
56
You can’t perform that action at this time.
0 commit comments