Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,7 @@ int set_as_metrics_policy_using_pyobject(as_error *err,
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

if (!report_dir) {
as_error_update(err, AEROSPIKE_ERR_PARAM, INVALID_ATTR_TYPE_ERROR_MSG,
"report_dir", "str");
Expand All @@ -1261,6 +1262,7 @@ int set_as_metrics_policy_using_pyobject(as_error *err,

uint64_t report_size_limit =
convert_pyobject_to_uint64_t(py_report_size_limit);
Py_DECREF(py_report_size_limit);
if (PyErr_Occurred()) {
as_error_update(err, AEROSPIKE_ERR_PARAM, INVALID_ATTR_TYPE_ERROR_MSG,
report_size_limit_attr_name, "unsigned 64-bit integer");
Expand All @@ -1278,6 +1280,7 @@ int set_as_metrics_policy_using_pyobject(as_error *err,
}

uint32_t interval = convert_pyobject_to_uint32_t(py_interval);
Py_DECREF(py_interval);
if (PyErr_Occurred()) {
as_error_update(err, AEROSPIKE_ERR_PARAM, INVALID_ATTR_TYPE_ERROR_MSG,
interval_field_name, "unsigned 32-bit integer");
Expand All @@ -1299,6 +1302,7 @@ int set_as_metrics_policy_using_pyobject(as_error *err,
}

uint8_t attr_value = convert_pyobject_to_uint8_t(py_attr_value);
Py_DECREF(py_attr_value);
if (PyErr_Occurred()) {
as_error_update(err, AEROSPIKE_ERR_PARAM,
INVALID_ATTR_TYPE_ERROR_MSG, uint8_field_names[i],
Expand Down
Loading