app/testpmd: fix allocation check in MTR parsing
authorJasvinder Singh <jasvinder.singh@intel.com>
Mon, 22 Jan 2018 15:15:04 +0000 (15:15 +0000)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 31 Jan 2018 22:34:47 +0000 (23:34 +0100)
Malloc() function might return NULL due to insufficient space. Therefore,
check for handling memory allocation failure is added.

Coverity issue: 257039
Fixes: e63b50162aa3 ("app/testpmd: clean metering and policing commands")

Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
app/test-pmd/cmdline_mtr.c

index 96a851b..f908fb3 100644 (file)
@@ -86,6 +86,8 @@ parse_dscp_table_entries(char *str, enum rte_mtr_color *dscp_table)
        /* Allocate memory for dscp table */
        dscp_table = (enum rte_mtr_color *)malloc(MAX_DSCP_TABLE_ENTRIES *
                sizeof(enum rte_mtr_color));
+       if (dscp_table == NULL)
+               return -1;
 
        while (1) {
                if (strcmp(token, "G") == 0 ||
@@ -105,8 +107,10 @@ parse_dscp_table_entries(char *str, enum rte_mtr_color *dscp_table)
                        break;
 
                token = strtok_r(str, PARSE_DELIMITER, &str);
-               if (token == NULL)
+               if (token == NULL) {
+                       free(dscp_table);
                        return -1;
+               }
        }
        return 0;
 }