Skip to content

Commit 18425ad

Browse files
committed
fix
1 parent e6143db commit 18425ad

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

agent/lib_aws_sdk_php.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ void nr_lib_aws_sdk_php_lambda_handle(nr_segment_t* auto_segment,
340340

341341
/* reconstruct the ARN */
342342
nr_aws_lambda_invoke(NR_EXECUTE_ORIG_ARGS, &cloud_attrs);
343-
if (!cloud_attrs.cloud_resource_id) {
343+
if (NULL == cloud_attrs.cloud_resource_id) {
344344
/* we do not want to instrument if we cannot reconstruct the ARN */
345345
return;
346346
}
@@ -352,6 +352,7 @@ void nr_lib_aws_sdk_php_lambda_handle(nr_segment_t* auto_segment,
352352
*/
353353
external_segment = nr_segment_start(NRPRG(txn), NULL, NULL);
354354
if (NULL == external_segment) {
355+
nr_free(cloud_attrs.cloud_resource_id);
355356
return;
356357
}
357358
/* re-use start time from auto_segment started in func_begin */
@@ -379,6 +380,7 @@ void nr_lib_aws_sdk_php_lambda_handle(nr_segment_t* auto_segment,
379380
}
380381
}
381382
nr_segment_external_end(&auto_segment, &external_params);
383+
nr_free(cloud_attrs.cloud_resource_id);
382384
}
383385

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

408411
/* verify arguments */
409412
if (!nr_php_is_zval_valid_array(call_args)) {
@@ -439,11 +442,17 @@ void nr_aws_lambda_invoke(NR_EXECUTE_PROTO, nr_segment_cloud_attrs_t* cloud_attr
439442
* Cannot get the needed data. Function name is required in the
440443
* argument, so this won't happen in normal operation
441444
*/
445+
nr_free(function_name);
446+
nr_free(accountID);
447+
nr_free(region);
448+
nr_free(qualifier);
442449
nr_regex_substrings_destroy(&matches);
443450
return;
444451
}
445452
if (nr_strempty(accountID)) {
453+
nr_free(accountID);
446454
accountID = NRINI(aws_account_id);
455+
using_account_id_ini = true;
447456
}
448457
if (nr_strempty(region)) {
449458
region_zval
@@ -474,6 +483,12 @@ void nr_aws_lambda_invoke(NR_EXECUTE_PROTO, nr_segment_cloud_attrs_t* cloud_attr
474483
}
475484

476485
nr_regex_substrings_destroy(&matches);
486+
nr_free(function_name);
487+
if (!using_account_id_ini) {
488+
nr_free(accountID);
489+
}
490+
nr_free(region);
491+
nr_free(qualifier);
477492
nr_php_zval_free(&region_zval);
478493
nr_php_zval_free(&qualifier_zval);
479494
}

agent/php_minit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ PHP_MINIT_FUNCTION(newrelic) {
716716
nr_guzzle4_minit(TSRMLS_C);
717717
nr_guzzle6_minit(TSRMLS_C);
718718
nr_laravel_minit(TSRMLS_C);
719+
nr_wordpress_minit();
719720
nr_php_set_opcode_handlers();
720721

721722
nrl_debug(NRL_INIT, "MINIT processing done");

agent/tests/test_lib_aws_sdk_php.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ NR_PHP_WRAPPER(aws_lambda_invoke_wrapper) {
8181
cloud_attrs.cloud_resource_id);
8282
}
8383
NR_PHP_WRAPPER_CALL;
84+
nr_free(cloud_attrs.cloud_resource_id);
8485
}
8586
NR_PHP_WRAPPER_END
8687

0 commit comments

Comments
 (0)