]> pilppa.com Git - libplpdevicebus.git/commitdiff
memory leak fixes
authorMika Laitio <lamikr@pilppa.org>
Wed, 15 Aug 2012 07:58:56 +0000 (10:58 +0300)
committerMika Laitio <lamikr@pilppa.org>
Wed, 15 Aug 2012 07:58:56 +0000 (10:58 +0300)
Signed-off-by: Mika Laitio <lamikr@pilppa.org>
src_client/DeviceManagerClient.cc
src_client/DeviceManagerClient.hh

index b318d88176d95789c287d28dcaf85490842c6783..3c47f4efba5abe2e88d8657368144fd10e971563 100644 (file)
@@ -44,7 +44,7 @@ DeviceManagerClient::~DeviceManagerClient() {
 }
 
 const std::list<plp::Device *> *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<plp::Device *> *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);
index fbfdff9644d6cb2c4f3cacf4c862e3e1fe8ded58..68fbd16396495ca5a314feaeddf873504ec4533e 100644 (file)
@@ -34,6 +34,11 @@ namespace plpdevicebus {
                        list<plp::Device *>     *_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<plp::Device *> *parse_device_list_msg(plpbus::BusMessage *dev_list_msg_param,
                                                                int *err_flg);
        };