Skip to content

Commit fd5c35b

Browse files
committed
don't store wraprec on op_array extension too soon
The op_array extension slot for function is not available until function's first call. Check if op_array extension slot is initialized before using it to store wraprec.
1 parent 88485df commit fd5c35b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

agent/php_user_instrument.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,15 @@ static nr_php_wraprec_hashmap_t* user_function_wrappers;
130130
static inline void nr_php_wraprec_lookup_set(nruserfn_t* wr,
131131
zend_function* zf) {
132132
nr_php_wraprec_hashmap_update(user_function_wrappers, zf, wr);
133-
// store the wraprec in the op_array extension for the duration of the request for later lookup
134133
// for situation when wraprec is added after first execution of the function
135-
ZEND_OP_ARRAY_EXTENSION(&zf->op_array, NR_PHP_PROCESS_GLOBALS(op_array_extension_handle)) = wr;
134+
// store the wraprec in the op_array extension for the duration of the request for later lookup
135+
// The op_array extension slot for function may not be initialized yet because it is
136+
// initialized only on the first call made to the function in that request. This would
137+
// mean that run_time_cache is NULL and wraprec cannot be stored yet! It will be stored
138+
// on the first call to the function when observer is registered for that function.
139+
if (NULL != RUN_TIME_CACHE(&zf->op_array)) {
140+
ZEND_OP_ARRAY_EXTENSION(&zf->op_array, NR_PHP_PROCESS_GLOBALS(op_array_extension_handle)) = wr;
141+
}
136142

137143
}
138144
static inline nruserfn_t* nr_php_wraprec_lookup_get(zend_function* zf) {

0 commit comments

Comments
 (0)