]> granicus.if.org Git - esp-idf/commitdiff
console: Free alloc'd memory after error conditions
authorAnuj Deshpande <anuj@espressif.com>
Mon, 30 Apr 2018 08:51:03 +0000 (14:21 +0530)
committerAnuj Deshpande <anuj@espressif.com>
Mon, 30 Apr 2018 08:51:03 +0000 (14:21 +0530)
Closes https://github.com/espressif/esp-idf/issues/1901

components/console/commands.c

index c52c7061da825cb58dba8c67ce3bf81304305d95..32fb86f0fe06888d07d3b3cd2e43ac7e86344f64 100644 (file)
@@ -91,9 +91,11 @@ esp_err_t esp_console_cmd_register(const esp_console_cmd_t *cmd)
         return ESP_ERR_NO_MEM;
     }
     if (cmd->command == NULL) {
+       free(item);
         return ESP_ERR_INVALID_ARG;
     }
     if (strchr(cmd->command, ' ') != NULL) {
+       free(item);
         return ESP_ERR_INVALID_ARG;
     }
     item->command = cmd->command;
@@ -186,10 +188,12 @@ esp_err_t esp_console_run(const char* cmdline, int* cmd_ret)
     size_t argc = esp_console_split_argv(s_tmp_line_buf, argv,
             s_config.max_cmdline_args);
     if (argc == 0) {
+       free(argv);
         return ESP_ERR_INVALID_ARG;
     }
     const cmd_item_t* cmd = find_command_by_name(argv[0]);
     if (cmd == NULL) {
+       free(argv);
         return ESP_ERR_NOT_FOUND;
     }
     *cmd_ret = (*cmd->func)(argc, argv);