Skip to content

Commit

Permalink
[CLIENT-2278] batch_operate(): fix memory error (#428)
Browse files Browse the repository at this point in the history
batch_operate() was trying to get the ttl property from batch write policy before checking that the policy is valid
  • Loading branch information
juliannguyen4 committed Apr 19, 2023
1 parent 8b1ebbe commit 898a7a5
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/main/client/batch_operate.c
Expand Up @@ -145,26 +145,6 @@ static PyObject *AerospikeClient_Batch_Operate_Invoke(
Py_ssize_t ops_size = PyList_Size(py_ops);
as_operations_inita(&ops, ops_size);

// The C client's batch write policy doesn't have a ttl option
// The correct way is to set the ttl inside the as_operations object
PyObject *py_ttl = PyDict_GetItemString(py_policy_batch_write, "ttl");
Py_XINCREF(py_ttl);
// Default ttl
if (py_ttl != NULL) {
if (PyLong_Check(py_ttl)) {
long ttl = PyLong_AsLong(py_ttl);
if (ttl > UINT32_MAX || ttl < 0) {
as_error_update(err, AEROSPIKE_ERR_PARAM,
"ttl is out of range. It must be a 32 bit "
"unsigned integer.");
Py_DECREF(py_ttl);
goto CLEANUP;
}
ops.ttl = ttl;
}
}
Py_XDECREF(py_ttl);

PyObject *br_instance = NULL;

if (!self || !self->as) {
Expand Down Expand Up @@ -240,6 +220,26 @@ static PyObject *AerospikeClient_Batch_Operate_Invoke(
&batch_write_exp_list_p) != AEROSPIKE_OK) {
goto CLEANUP;
}

// The C client's batch write policy doesn't have a ttl option
// The correct way is to set the ttl inside the as_operations object
PyObject *py_ttl = PyDict_GetItemString(py_policy_batch_write, "ttl");
Py_XINCREF(py_ttl);
// Default ttl
if (py_ttl != NULL) {
if (PyLong_Check(py_ttl)) {
long ttl = PyLong_AsLong(py_ttl);
if (ttl > UINT32_MAX || ttl < 0) {
as_error_update(err, AEROSPIKE_ERR_PARAM,
"ttl is out of range. It must be a 32 bit "
"unsigned integer.");
Py_DECREF(py_ttl);
goto CLEANUP;
}
ops.ttl = ttl;
}
}
Py_XDECREF(py_ttl);
}

// import batch_records helper
Expand Down

0 comments on commit 898a7a5

Please sign in to comment.