Skip to content

Commit f160b3b

Browse files
committed
fix(agent): Move dtors closer to where the values are initialized
1 parent 90da3b7 commit f160b3b

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

agent/lib_php_amqplib.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,6 @@ static inline void nr_php_amqplib_insert_dt_headers(zval* amqp_msg) {
281281
return;
282282
}
283283

284-
/*
285-
* Get application+_headers string in zval form for use with nr_php_call
286-
*/
287-
ZVAL_STRING(&application_headers_zpd, "application_headers");
288-
289284
/*
290285
* The application_headers are stored in an encoded PhpAmqpLib\Wire\AMQPTable
291286
* object
@@ -308,18 +303,32 @@ static inline void nr_php_amqplib_insert_dt_headers(zval* amqp_msg) {
308303
"})();",
309304
&amqp_table_retval_zpd, "newrelic.amqplib.add_empty_headers");
310305

311-
if (FAILURE == retval
312-
|| !nr_php_is_zval_valid_object(&amqp_table_retval_zpd)) {
306+
if (FAILURE == retval) {
307+
nrl_verbosedebug(NRL_INSTRUMENT,
308+
"No application headers in AMQPTable, but couldn't "
309+
"create one. Exit.");
310+
goto end;
311+
}
312+
if (!nr_php_is_zval_valid_object(&amqp_table_retval_zpd)) {
313313
nrl_verbosedebug(NRL_INSTRUMENT,
314314
"No application headers in AMQPTable, but couldn't "
315315
"create one. Exit.");
316+
zval_ptr_dtor(&amqp_table_retval_zpd);
316317
goto end;
317318
}
319+
/*
320+
* Get application+_headers string in zval form for use with nr_php_call
321+
*/
322+
ZVAL_STRING(&application_headers_zpd, "application_headers");
318323
/*
319324
* Set the valid AMQPTable on the AMQPMessage.
320325
*/
321326
retval_set_property_zvf = nr_php_call(
322327
amqp_msg, "set", &application_headers_zpd, &amqp_table_retval_zpd);
328+
329+
zval_ptr_dtor(&application_headers_zpd);
330+
zval_ptr_dtor(&amqp_table_retval_zpd);
331+
323332
if (NULL == retval_set_property_zvf) {
324333
nrl_verbosedebug(NRL_INSTRUMENT,
325334
"AMQPMessage had no application_headers AMQPTable, but "
@@ -396,8 +405,6 @@ static inline void nr_php_amqplib_insert_dt_headers(zval* amqp_msg) {
396405
end:
397406
nr_php_zval_free(&dt_headers_zvf);
398407
nr_php_zval_free(&retval_set_property_zvf);
399-
zval_ptr_dtor(&application_headers_zpd);
400-
zval_ptr_dtor(&amqp_table_retval_zpd);
401408
}
402409

403410
/*

0 commit comments

Comments
 (0)