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

index 3c47f4efba5abe2e88d8657368144fd10e971563..955128239923d16578b07d00b5135fcd6795017f 100644 (file)
@@ -45,8 +45,6 @@ DeviceManagerClient::~DeviceManagerClient() {
 
 const std::list<plp::Device *> *DeviceManagerClient::get_device_list(BusClient *client_param,
                                                                int *err_flg) {
-       //send_request__get_device_list(client_param);
-
        BusMessage      *msg_req;
        BusMessage      *msg_rsp;
 
@@ -77,13 +75,12 @@ void DeviceManagerClient::parse_device_data_msg(BusMessage *msg_param,
                if (data_str.empty() == false) {
                        data    = Data::parse_string(data_str);
                }
-               if (data == NULL) {
-                       data    = new Data(0);
+               if (data != NULL) {
+                       result->add(data);
+                       log_debug("%s\n", description.c_str());
+                       data->printout();
+                       delete(data);
                }
-               result->add(data);
-               log_debug("%s\n", description.c_str());
-               data->printout();
-               delete(data);
        }
 }
 
@@ -141,11 +138,13 @@ list<Device *> *DeviceManagerClient::parse_device_list_msg(BusMessage *msg_param
        Data                            *data;
        list<Device *>                  *ret_val;
 
+       ret_val = new list<Device *>;
        count   = msg_param->get_long_parameter(RSP__DEVICE_LIST__DEVICE_COUNT, err_flg);
        log_debug("device count: %ld\n", count);
-       ret_val = new list<Device *>;
        if (*err_flg == PLP_OK) {
                for (ii = 0; ii < count; ii++) {
+                       data    = NULL;
+
                        key.str("");
                        key << RSP__DEVICE_LIST__ID << ii;
                        id      = msg_param->get_string_parameter(key.str(), err_flg);
@@ -185,14 +184,11 @@ list<Device *> *DeviceManagerClient::parse_device_list_msg(BusMessage *msg_param
                        if (*err_flg == PLP_OK) {
                                data    = Data::parse_string(datastr);
                                if (data == NULL) {
-                                       log_error("Failed to parse data items for the device: %s\n", id.c_str());
-                                       *err_flg = PLP_ERR;
-                                       break;
+                                       log_error("No data available for the device: %s\n", id.c_str());
                                }
                        }
                        else {
                                log_error("No data available for the device: %s\n", id.c_str());
-                               data    = new Data(0);
                        }
                        dev     = new DeviceData(id, type, name, state, data);
                        ret_val->push_back(dev);