From 8c266e62fab758a10fd2e95862baf52fb9c8d891 Mon Sep 17 00:00:00 2001 From: Mika Laitio Date: Wed, 15 Aug 2012 10:59:27 +0300 Subject: [PATCH] memory leak fixes Signed-off-by: Mika Laitio --- src_client/NetworkServiceClient_W1.cc | 39 ++++++++++++++------------- src_server/NetworkServiceServer_W1.cc | 2 +- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src_client/NetworkServiceClient_W1.cc b/src_client/NetworkServiceClient_W1.cc index 8515ac7..6ed247d 100644 --- a/src_client/NetworkServiceClient_W1.cc +++ b/src_client/NetworkServiceClient_W1.cc @@ -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 *)dev_lst)->begin(); dev_iter != ((list *)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 *)dev_lst)->begin(); dev_iter != ((list *)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); } diff --git a/src_server/NetworkServiceServer_W1.cc b/src_server/NetworkServiceServer_W1.cc index 3e88022..f328592 100644 --- a/src_server/NetworkServiceServer_W1.cc +++ b/src_server/NetworkServiceServer_W1.cc @@ -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(); } } -- 2.41.1