]> pilppa.org Git - libplp.git/commitdiff
memory leak fixes
authorMika Laitio <lamikr@pilppa.org>
Mon, 14 Mar 2011 07:01:09 +0000 (09:01 +0200)
committerMika Laitio <lamikr@pilppa.org>
Mon, 14 Mar 2011 07:01:09 +0000 (09:01 +0200)
Signed-off-by: Mika Laitio <lamikr@pilppa.org>
src/DeviceConfig.hh
src/config.c
src_test/test_config2.c

index 90ff28d31edcd92441d441a8c8aace119f6e9ed4..194b8a7c6aaabd6fdec6106a9245055661262374 100644 (file)
@@ -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"
index c099d97fbe022b89c12b0549667210427b38c987..df77e3b236b3660b7658a2945e82c92786365d2a 100644 (file)
@@ -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;
                                                        }
index 2bf367b0d62e864c043dae1d3d7dced058200ac6..32e1d931a467592e3e71afba11444f6de8f104c8 100644 (file)
@@ -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;
                                                        }