Fix to check memory allocation failure 67/224367/1 accepted/tizen/unified/20200210.131720 submit/tizen/20200210.075209
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Mon, 10 Feb 2020 06:28:36 +0000 (15:28 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Mon, 10 Feb 2020 06:28:38 +0000 (15:28 +0900)
The strdup() can be failed and return NULL. Not to access wrong
memory, explictly check memory allocation failure.

Change-Id: I2917cf0cebd6488004b653c29137c0acbb56074e
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
src/main.c

index 80267db..32c2473 100644 (file)
@@ -39,8 +39,13 @@ int _main(int argc, char *argv[])
                                if (opt_table)
                                        free(opt_table);
                                opt_table = strdup(optarg);
-                               if (opt_table)
+                               if (opt_table) {
                                        part_table = opt_table;
+                               } else {
+                                       fprintf(stderr, "Out of memory\n");
+                                       ret = -1;
+                                       goto out;
+                               }
                        } else {
                                fprintf(stderr,
                                        "path should be specified with '-i'\n");