Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(agent): Fix nr_header_create_distributed_trace_map mem leak when hashmap is destroyed #1017

Merged
merged 2 commits into from
Feb 7, 2025

Conversation

zsistla
Copy link
Contributor

@zsistla zsistla commented Feb 6, 2025

This function created a new hashmap, but didn's pass the string dtor in so any strdupped values were not being freed when the hashmap was destroyed.

valgrind output from a multiverse run showed:

==220== by 0x6AA4680: nr_strdup (util_memory.c:156)
==220== by 0x6A83BD3: nr_header_create_distributed_trace_map (nr_header.c:60)
==220== by 0x6A45D28: nr_php_amqplib_retrieve_dt_headers (lib_php_amqplib.c:503)
==220== by 0x6A45D28: nr_rabbitmq_basic_get (lib_php_amqplib.c:742)
==220== by 0x6A74993: nr_zend_call_orig_execute_special (php_user_instrument.c:105)
==220== by 0x6A52EAA: nr_php_instrument_func_end (php_execute.c:2086)
==220== by 0x6A54D5B: nr_php_observer_fcall_end (php_execute.c:2188)
==220== by 0x71D7ED: zend_observer_fcall_end (in /usr/local/bin/php)
==220== by 0x6E79FF: execute_ex (in /usr/local/bin/php)
==220== by 0x6F0B42: zend_execute (in /usr/local/bin/php)
==220== by 0x67C06F: zend_execute_scripts (in /usr/local/bin/php)
==220== by 0x60FA3D: php_execute_script (in /usr/local/bin/php)

after applying the fix, valgrind had no issues.

This function created a new hashmap, but didn's pass the string dtor in so any strdupped values were not being freed when the hashmap was destroyed.
@newrelic-php-agent-bot
Copy link

newrelic-php-agent-bot commented Feb 6, 2025

Test Suite Status Result
Multiverse 8/8 passing
SOAK 72/72 passing

@lavarou
Copy link
Member

lavarou commented Feb 6, 2025

Nice find! Please add unit tests for nr_header_create_distributed_trace_map to axiom/tests/test_header.c.

@codecov-commenter
Copy link

codecov-commenter commented Feb 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.00%. Comparing base (b0184fd) to head (4de95b2).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #1017   +/-   ##
=======================================
  Coverage   78.00%   78.00%           
=======================================
  Files         197      197           
  Lines       27424    27424           
=======================================
  Hits        21392    21392           
  Misses       6032     6032           
Flag Coverage Δ
agent-for-php-7.2 78.15% <100.00%> (ø)
agent-for-php-7.3 78.17% <100.00%> (ø)
agent-for-php-7.4 77.88% <100.00%> (ø)
agent-for-php-8.0 77.24% <100.00%> (ø)
agent-for-php-8.1 77.74% <100.00%> (ø)
agent-for-php-8.2 77.35% <100.00%> (ø)
agent-for-php-8.3 77.35% <100.00%> (ø)
agent-for-php-8.4 77.37% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@lavarou lavarou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lavarou lavarou added this to the next-release milestone Feb 6, 2025
@lavarou lavarou changed the title fix(axiom): Fix nr_header_create_distributed_trace_map mem leak when hashmap is destroyed fix(agent): Fix nr_header_create_distributed_trace_map mem leak when hashmap is destroyed Feb 6, 2025
@zsistla zsistla merged commit 52a6e23 into dev Feb 7, 2025
65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants