From dafdf7ba4b29d378407ca2f8be7821258c154d2c Mon Sep 17 00:00:00 2001 From: Mika Laitio Date: Wed, 15 Aug 2012 10:58:56 +0300 Subject: [PATCH] memory leak fixes Signed-off-by: Mika Laitio --- src_client/DeviceManagerClient.cc | 53 +++++++++++++++++++------------ src_client/DeviceManagerClient.hh | 5 +++ 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src_client/DeviceManagerClient.cc b/src_client/DeviceManagerClient.cc index b318d88..3c47f4e 100644 --- a/src_client/DeviceManagerClient.cc +++ b/src_client/DeviceManagerClient.cc @@ -44,7 +44,7 @@ DeviceManagerClient::~DeviceManagerClient() { } const std::list *DeviceManagerClient::get_device_list(BusClient *client_param, - int *err_flg) { + int *err_flg) { //send_request__get_device_list(client_param); BusMessage *msg_req; @@ -61,32 +61,43 @@ const std::list *DeviceManagerClient::get_device_list(BusClient * return _device_list; } -DataRange *DeviceManagerClient::parse_device_data_msg(BusMessage *msg_param, - int *err_flg) { - Data *data; +void DeviceManagerClient::parse_device_data_msg(BusMessage *msg_param, + DataRange *result, + string key, + int *err_flg, + string description) { string data_str; - DataRange *ret_val; + Data *data; *err_flg = PLP_ERR; - ret_val = NULL; - if (msg_param != NULL) { + data = NULL; + if ((msg_param != NULL) && + (result != NULL)) { data_str = msg_param->get_string_parameter(RSP__GET_LATEST_DATA__VALUE, err_flg); - data = Data::parse_string(data_str); - ret_val = new DataRange(data); - log_debug("latest data\n"); + if (data_str.empty() == false) { + data = Data::parse_string(data_str); + } + if (data == NULL) { + data = new Data(0); + } + result->add(data); + log_debug("%s\n", description.c_str()); data->printout(); + delete(data); + } +} - data_str = msg_param->get_string_parameter(RSP__GET_LATEST_DATA__MIN_VALUE, err_flg); - data = Data::parse_string(data_str); - ret_val->add(data); - log_debug("min data\n"); - data->printout(); +DataRange *DeviceManagerClient::parse_device_data_msg(BusMessage *msg_param, + int *err_flg) { + DataRange *ret_val; - data_str = msg_param->get_string_parameter(RSP__GET_LATEST_DATA__MAX_VALUE, err_flg); - data = Data::parse_string(data_str); - ret_val->add(data); - log_debug("max data\n"); - data->printout(); + *err_flg = PLP_ERR; + ret_val = NULL; + if (msg_param != NULL) { + ret_val = new DataRange(); + parse_device_data_msg(msg_param, ret_val, RSP__GET_LATEST_DATA__VALUE, err_flg, "latest data"); + parse_device_data_msg(msg_param, ret_val, RSP__GET_LATEST_DATA__MIN_VALUE, err_flg, "min data value"); + parse_device_data_msg(msg_param, ret_val, RSP__GET_LATEST_DATA__MAX_VALUE, err_flg, "max data value"); *err_flg = PLP_OK; } @@ -107,7 +118,7 @@ Data *DeviceManagerClient::get_latest_data(BusClient *client_param, msg_req->add_string_parameter(REQ__GET_LATEST_DATA__ID, device_id_param.c_str()); client_param->send_message_and_wait_response(msg_req, &msg_rsp); dr = parse_device_data_msg(msg_rsp, err_flg); - ret_val = dr->get_first()->clone(); + ret_val = dr->get_first(); delete(dr); delete(msg_req); delete(msg_rsp); diff --git a/src_client/DeviceManagerClient.hh b/src_client/DeviceManagerClient.hh index fbfdff9..68fbd16 100644 --- a/src_client/DeviceManagerClient.hh +++ b/src_client/DeviceManagerClient.hh @@ -34,6 +34,11 @@ namespace plpdevicebus { list *_device_list; DataRange *parse_device_data_msg(BusMessage *msg_param, int *err_flg); + void parse_device_data_msg(BusMessage *msg_param, + DataRange *result, + string key, + int *err_flg, + string description); list *parse_device_list_msg(plpbus::BusMessage *dev_list_msg_param, int *err_flg); }; -- 2.41.1