Skip to content

Commit

Permalink
memory leak (#643) (#645)
Browse files Browse the repository at this point in the history
* memory leak (#643)

Signed-off-by: Tomoya.Fujita <[email protected]>

Co-authored-by: Chen Lihui <[email protected]>
  • Loading branch information
fujitatomoya and Chen Lihui authored Dec 14, 2020
1 parent 1b4e188 commit 71ba65d
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions rclpy/src/rclpy/_rclpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -3436,28 +3436,14 @@ rclpy_take_raw_with_info(rcl_subscription_t * subscription, rmw_message_info_t *
static PyObject *
rclpy_message_info_to_dict(rmw_message_info_t * message_info)
{
PyObject * dict = PyDict_New();
PyObject * dict = Py_BuildValue(
"{s:L,s:L}",
"source_timestamp", message_info->source_timestamp,
"received_timestamp", message_info->received_timestamp);
if (dict == NULL) {
PyErr_Format(PyExc_RuntimeError, "Failed to create dictionary object");
PyErr_Format(PyExc_RuntimeError, "Failed to create dictionary object for message info");
return NULL;
}

// we bail out at the end in case of errors
PyObject * source_timestamp = PyLong_FromLongLong(message_info->source_timestamp);
if (source_timestamp != NULL) {
PyDict_SetItemString(dict, "source_timestamp", source_timestamp);
}
PyObject * received_timestamp = PyLong_FromLongLong(message_info->source_timestamp);
if (received_timestamp != NULL) {
PyDict_SetItemString(dict, "received_timestamp", source_timestamp);
}

// check for errors
if (source_timestamp == NULL || received_timestamp == NULL) {
Py_DECREF(dict);
dict = NULL;
}

return dict;
}

Expand Down

0 comments on commit 71ba65d

Please sign in to comment.