Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ZNeumann committed Feb 26, 2025
1 parent e6143db commit 18425ad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
17 changes: 16 additions & 1 deletion agent/lib_aws_sdk_php.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void nr_lib_aws_sdk_php_lambda_handle(nr_segment_t* auto_segment,

/* reconstruct the ARN */
nr_aws_lambda_invoke(NR_EXECUTE_ORIG_ARGS, &cloud_attrs);
if (!cloud_attrs.cloud_resource_id) {
if (NULL == cloud_attrs.cloud_resource_id) {
/* we do not want to instrument if we cannot reconstruct the ARN */
return;
}
Expand All @@ -352,6 +352,7 @@ void nr_lib_aws_sdk_php_lambda_handle(nr_segment_t* auto_segment,
*/
external_segment = nr_segment_start(NRPRG(txn), NULL, NULL);
if (NULL == external_segment) {
nr_free(cloud_attrs.cloud_resource_id);
return;
}
/* re-use start time from auto_segment started in func_begin */
Expand Down Expand Up @@ -379,6 +380,7 @@ void nr_lib_aws_sdk_php_lambda_handle(nr_segment_t* auto_segment,
}
}
nr_segment_external_end(&auto_segment, &external_params);
nr_free(cloud_attrs.cloud_resource_id);
}

/* This stores the compiled regex to parse AWS ARNs. The compilation happens when
Expand All @@ -404,6 +406,7 @@ void nr_aws_lambda_invoke(NR_EXECUTE_PROTO, nr_segment_cloud_attrs_t* cloud_attr
char* qualifier = NULL;
zval* qualifier_zval = NULL;
char* accountID = NULL;
bool using_account_id_ini = false;

/* verify arguments */
if (!nr_php_is_zval_valid_array(call_args)) {
Expand Down Expand Up @@ -439,11 +442,17 @@ void nr_aws_lambda_invoke(NR_EXECUTE_PROTO, nr_segment_cloud_attrs_t* cloud_attr
* Cannot get the needed data. Function name is required in the
* argument, so this won't happen in normal operation
*/
nr_free(function_name);
nr_free(accountID);
nr_free(region);
nr_free(qualifier);
nr_regex_substrings_destroy(&matches);
return;
}
if (nr_strempty(accountID)) {
nr_free(accountID);
accountID = NRINI(aws_account_id);
using_account_id_ini = true;
}
if (nr_strempty(region)) {
region_zval
Expand Down Expand Up @@ -474,6 +483,12 @@ void nr_aws_lambda_invoke(NR_EXECUTE_PROTO, nr_segment_cloud_attrs_t* cloud_attr
}

nr_regex_substrings_destroy(&matches);
nr_free(function_name);
if (!using_account_id_ini) {
nr_free(accountID);
}
nr_free(region);
nr_free(qualifier);
nr_php_zval_free(&region_zval);
nr_php_zval_free(&qualifier_zval);
}
Expand Down
1 change: 1 addition & 0 deletions agent/php_minit.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ PHP_MINIT_FUNCTION(newrelic) {
nr_guzzle4_minit(TSRMLS_C);
nr_guzzle6_minit(TSRMLS_C);
nr_laravel_minit(TSRMLS_C);
nr_wordpress_minit();
nr_php_set_opcode_handlers();

nrl_debug(NRL_INIT, "MINIT processing done");
Expand Down
1 change: 1 addition & 0 deletions agent/tests/test_lib_aws_sdk_php.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ NR_PHP_WRAPPER(aws_lambda_invoke_wrapper) {
cloud_attrs.cloud_resource_id);
}
NR_PHP_WRAPPER_CALL;
nr_free(cloud_attrs.cloud_resource_id);
}
NR_PHP_WRAPPER_END

Expand Down

0 comments on commit 18425ad

Please sign in to comment.