Skip to content

Commit

Permalink
fix(agent): add an unperist macro
Browse files Browse the repository at this point in the history
  • Loading branch information
zsistla committed Jan 31, 2025
1 parent 095f82d commit 71e5e02
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions agent/lib_php_amqplib.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
*/
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO /* PHP8.0+ */
#define ENSURE_PERSISTENCE(x) x
#define UNDO_PERSISTENCE(x)
#else
#define ENSURE_PERSISTENCE(x) nr_strdup(x)
#define UNDO_PERSISTENCE(x) nr_free(x);
#endif

/*
Expand Down Expand Up @@ -247,11 +249,6 @@ NR_PHP_WRAPPER(nr_rabbitmq_basic_publish) {
}

end:
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO
/* PHP 8+ */
/* gnu compiler needed closure. */
;
#else
/*
* Because we had to strdup values to persist them beyond NR_PHP_WRAPPER_CALL,
* now we destroy them. There isn't a separate function to destroy all since
Expand All @@ -260,10 +257,9 @@ NR_PHP_WRAPPER(nr_rabbitmq_basic_publish) {
* strdup server_address, destination_name, and
* messaging_destination_routing_key.
*/
nr_free(message_params.server_address);
nr_free(message_params.destination_name);
nr_free(message_params.messaging_destination_routing_key);
#endif
UNDO_PERSISTENCE(message_params.server_address);
UNDO_PERSISTENCE(message_params.destination_name);
UNDO_PERSISTENCE(message_params.messaging_destination_routing_key);
}
NR_PHP_WRAPPER_END

Expand Down Expand Up @@ -366,21 +362,15 @@ NR_PHP_WRAPPER(nr_rabbitmq_basic_get) {
nr_segment_message_end(&message_segment, &message_params);

end:
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO
/* PHP 8+ */
/* gnu compiler needed closure. */
;
#else
/*
* Because we had to strdup values to persist them beyond NR_PHP_WRAPPER_CALL,
* now we destroy them. There isn't a separate function to destroy all since
* some of the params are string literals and we don't want to strdup
* everything if we don't have to. RabbitMQ basic_get PHP 7.x will only strdup
* server_address and destination_name.
*/
nr_free(message_params.server_address);
nr_free(message_params.destination_name);
#endif
UNDO_PERSISTENCE(message_params.server_address);
UNDO_PERSISTENCE(message_params.destination_name);
}
NR_PHP_WRAPPER_END

Expand Down

0 comments on commit 71e5e02

Please sign in to comment.