Skip to content

Commit

Permalink
fix(agent): fix memleak in Laravel Queue instrumentation (#1014)
Browse files Browse the repository at this point in the history
Free strings that were strdup-ed but not being freed.
  • Loading branch information
zsistla authored Feb 5, 2025
1 parent 94a41f5 commit b0184fd
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions agent/fw_laravel_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ static void nr_laravel_queue_set_cat_txn(zval* job TSRMLS_DC) {
}

if (headers.dt_payload || headers.traceparent) {

nr_hashmap_t* header_map = nr_header_create_distributed_trace_map(
headers.dt_payload, headers.traceparent, headers.tracestate);

Expand Down Expand Up @@ -225,6 +224,11 @@ static char* nr_laravel_queue_job_txn_name(zval* job TSRMLS_DC) {

name = nr_formatf("%s (%s:%s)", resolve_name, connection_name, queue_name);

nr_free(connection_name);
nr_free(resolve_name);
nr_free(queue_name);

/* Caller is responsible for freeing name. */
return name;
}

Expand Down Expand Up @@ -252,6 +256,7 @@ NR_PHP_WRAPPER(nr_laravel_queue_syncqueue_raiseBeforeJobEvent_before) {

job = nr_php_arg_get(1, NR_EXECUTE_ORIG_ARGS);

/* txn_name needs to be freed by the caller. */
txn_name = nr_laravel_queue_job_txn_name(job);

/*
Expand All @@ -271,6 +276,7 @@ NR_PHP_WRAPPER(nr_laravel_queue_syncqueue_raiseBeforeJobEvent_before) {
NR_OK_TO_OVERWRITE);
}
nr_php_arg_release(&job);
nr_free(txn_name);
NR_PHP_WRAPPER_CALL;
}
NR_PHP_WRAPPER_END
Expand Down Expand Up @@ -317,6 +323,7 @@ NR_PHP_WRAPPER(nr_laravel_queue_worker_raiseBeforeJobEvent_after) {
nr_txn_set_path("Laravel", NRPRG(txn), txn_name, NR_PATH_TYPE_CUSTOM,
NR_OK_TO_OVERWRITE);
}
nr_free(txn_name);
nr_php_arg_release(&job);
NR_PHP_WRAPPER_CALL;
}
Expand Down Expand Up @@ -574,7 +581,7 @@ NR_PHP_WRAPPER(nr_laravel_queue_worker_process) {
* as the first parameter.
*/
char* connection_name = NULL;
char* job_name;
char* job_name = NULL;
char* txn_name = NULL;

connection = nr_php_arg_get(1, NR_EXECUTE_ORIG_ARGS TSRMLS_CC);
Expand Down

0 comments on commit b0184fd

Please sign in to comment.