From: Mika Laitio Date: Mon, 14 Mar 2011 07:01:09 +0000 (+0200) Subject: memory leak fixes X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=45dab65b4663bd3a4115d62effd430441e43fa23;p=libplp.git memory leak fixes Signed-off-by: Mika Laitio --- diff --git a/src/DeviceConfig.hh b/src/DeviceConfig.hh index 90ff28d..194b8a7 100644 --- a/src/DeviceConfig.hh +++ b/src/DeviceConfig.hh @@ -21,7 +21,7 @@ enum EnumSummaryCalculationType {SUM, DELTA, MIN, MAX, MEAN}; const std::string SUMMARY_PERIOD_NAMES_ARRAY[] = {"yearly", "monthly", "daily", "minutely", "secondly"}; const std::string CALCULATION_TYPE_NAMES_ARRAY[] = {"sum", "delta", "min", "max", "mean"}; -#define DEVICE_CONFIG__FILE_NAME "dev_cfg.txt" +#define DEVICE_CONFIG__FILE_NAME "device_cfg" #define DEVICE_CONFIG__SECTION_TYPE "device" #define DEVICE_CONFIG__SECTION_NAME "base_data" #define DEVICE_CONFIG_VALUE_KEY__TYPE "type" diff --git a/src/config.c b/src/config.c index c099d97..df77e3b 100644 --- a/src/config.c +++ b/src/config.c @@ -26,12 +26,15 @@ static int uci_create_named_section(struct uci_context *ctx, const char *conf_fi len = len + strlen(section_name); len = len + 1; cmd_data = malloc(len); - snprintf(cmd_data, len, "%s.%s=%s", conf_file_name, section_name, section_type); - if (uci_lookup_ptr(ctx, &ptr, cmd_data, true) == UCI_OK) { - ret_val = uci_set(ctx, &ptr); - if (ret_val == UCI_OK) { - //ret_val = uci_save(ctx, ptr.p); + if (cmd_data != NULL) { + snprintf(cmd_data, len, "%s.%s=%s", conf_file_name, section_name, section_type); + if (uci_lookup_ptr(ctx, &ptr, cmd_data, true) == UCI_OK) { + ret_val = uci_set(ctx, &ptr); + if (ret_val == UCI_OK) { + //ret_val = uci_save(ctx, ptr.p); + } } + free(cmd_data); } } return ret_val; @@ -114,7 +117,7 @@ bool set_config_value(const char *conf_dir_name, ptr.option = key; if (uci_lookup_ptr(ctx, &ptr, NULL, false) == UCI_OK) { - ptr.value = strdup(value); + ptr.value = value; uci_set(ctx, &ptr); save = true; } diff --git a/src_test/test_config2.c b/src_test/test_config2.c index 2bf367b..32e1d93 100644 --- a/src_test/test_config2.c +++ b/src_test/test_config2.c @@ -61,12 +61,14 @@ static int uci_create_named_section(struct uci_context *ctx, const char *conf_fi len = len + strlen(section_name); len = len + 1; cmd_data = malloc(len); - snprintf(cmd_data, len, "%s.%s=%s", conf_file_name, section_name, section_type); - if (uci_lookup_ptr(ctx, &ptr, cmd_data, true) == UCI_OK) { - ret_val = uci_set(ctx, &ptr); - if (ret_val == UCI_OK) { - //ret_val = uci_save(ctx, ptr.p); + if (cmd_data != NULL) { + snprintf(cmd_data, len, "%s.%s=%s", conf_file_name, section_name, section_type); + if (uci_lookup_ptr(ctx, &ptr, cmd_data, true) == UCI_OK) { + ret_val = uci_set(ctx, &ptr); + if (ret_val == UCI_OK) { + } } + free(cmd_data); } } return ret_val; @@ -149,7 +151,7 @@ bool set_config_value2(const char *conf_dir_name, ptr.option = key; if (uci_lookup_ptr(ctx, &ptr, NULL, false) == UCI_OK) { - ptr.value = strdup(value); + ptr.value = value; uci_set(ctx, &ptr); save = true; }