]> pilppa.org Git - libplp.git/blobdiff - src/config.c
memory leak fixes
[libplp.git] / src / config.c
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;
                                                        }