Skip to content

Conversation

DomPeliniAerospike
Copy link
Collaborator

Decrementing reference for dangling pointers in metrics_policy intialization

Decrementing reference for dangling pointers in metrics_policy intialization
@codecov-commenter
Copy link

codecov-commenter commented Aug 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.00%. Comparing base (f762c03) to head (b6118c1).
⚠️ Report is 7 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #818      +/-   ##
==========================================
- Coverage   82.03%   82.00%   -0.03%     
==========================================
  Files          99       99              
  Lines       14724    13912     -812     
==========================================
- Hits        12079    11409     -670     
+ Misses       2645     2503     -142     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@juliannguyen4 juliannguyen4 changed the title Fixed dangling pointers in policy.c [CLIENT-2159] Fix reference count leaks in policy.c Aug 20, 2025
Copy link
Collaborator

@juliannguyen4 juliannguyen4 left a comment

Choose a reason for hiding this comment

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

Hey Dominic, just one issue I found. Otherwise LGTM

goto error;
}
const char *report_dir = convert_pyobject_to_str(py_report_dir);
Py_DECREF(py_report_dir);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Py_DECREF(py_report_dir);

This may cause a memory error later when we try to read the string pointed to by report_dir, because the string is wrapped around the py_report_dir object. If py_report_dir gets garbage collected, then the string would become invalid:

https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_AsUTF8AndSize
https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_AsUTF8

So you would need to move this Py_DECREF to after the last time we read from report_dir, which is the line with strcpy

@juliannguyen4 juliannguyen4 changed the title [CLIENT-2159] Fix reference count leaks in policy.c [CLIENT-2159] Fix reference count leaks when a user passes in a MetricsPolicy to client.enable_metrics() Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants