]> pilppa.com Git - nws-w1.git/commitdiff
memory leak fixes
authorMika Laitio <lamikr@pilppa.org>
Wed, 15 Aug 2012 07:59:27 +0000 (10:59 +0300)
committerMika Laitio <lamikr@pilppa.org>
Wed, 15 Aug 2012 07:59:27 +0000 (10:59 +0300)
Signed-off-by: Mika Laitio <lamikr@pilppa.org>
src_client/NetworkServiceClient_W1.cc
src_server/NetworkServiceServer_W1.cc

index 8515ac7400e82cd010f8d37c080fdf035b811efe..6ed247df5bdd6f0cc045da2258a65d4a2d3efb9d 100644 (file)
@@ -28,33 +28,36 @@ int main(int argc, char** argv)
        Device                          *device;
        string                          id;
        int                             err_flg;
+       Data                            *data;
 
+       dev_lst         = NULL;
        controller      = new DeviceManagerController();
        if (controller != NULL) {
                dev_lst = controller->get_device_list(&err_flg);
-               if (err_flg == PLP_OK) {
-                       if (dev_lst != NULL) {
-                               for (dev_iter = ((list<Device *> *)dev_lst)->begin(); dev_iter != ((list<Device *> *)dev_lst)->end(); dev_iter++) {
-                                       device  = (Device *)*dev_iter;
-                                       id      = device->get_id();
-                                       device->printout();
-                                       log_info("id: %s\n", id.c_str());
-                                       controller->get_latest_data(id, &err_flg);
-                                       if (err_flg == PLP_OK) {
-                                               log_info("latest data:\n");
-                                       }
-                                       else {
-                                               log_error("Could not get latest data for device id: %s\n", id.c_str());
-                                       }
+               if ((err_flg == PLP_OK) &&
+                    (dev_lst != NULL)) {
+                       for (dev_iter = ((list<Device *> *)dev_lst)->begin(); dev_iter != ((list<Device *> *)dev_lst)->end(); dev_iter++) {
+                               device  = (Device *)*dev_iter;
+                               id      = device->get_id();
+                               device->printout();
+                               log_info("id: %s\n", id.c_str());
+                               data    = controller->get_latest_data(id, &err_flg);
+                               if ((data != NULL) &&
+                                   (err_flg == PLP_OK)) {
+                                       log_info("latest data:\n");
+                                       data->printout();
+                                       delete(data);
+                               }
+                               else {
+                                       log_error("Could not get latest data for device id: %s\n", id.c_str());
                                }
-                       }
-                       else {
-                               log_error("Could not get device list, device list NULL");
                        }
                }
                else {
-                       log_error("Could not get device list, error code: %d", err_flg);
+                       log_error("Could not get device list, device list NULL or error code returned.\n");
                }
+               //if (dev_lst != NULL)
+               //      delete(dev_lst);
                delete(controller);
                sleep(3);
        }
index 3e8802243bacebe3e8fb4cb66db65779c68b0ee3..f328592b4cb998f3a9231b68aa9d18fe462f4645 100644 (file)
@@ -53,7 +53,7 @@ int main(int argc, char** argv)
                succ    = parse_long(argv[2], &interval_sec);
                if (succ == false) {
                        interval_sec    = DEFAULT_READ_INTERVAL_SEC;
-                       log_error("failed to parse read interval parameter, using default value: %ld", interval_sec);
+                       log_error("failed to parse read interval parameter, using default value: %ld\n", interval_sec);
                        printout_usage();
                }
        }