Handle memory allocation fail cases 60/307360/2
authorSung-hun Kim <sfoon.kim@samsung.com>
Thu, 7 Mar 2024 06:46:43 +0000 (15:46 +0900)
committerSung-hun Kim <sfoon.kim@samsung.com>
Fri, 8 Mar 2024 02:05:57 +0000 (11:05 +0900)
This patch fixes a svace issue (wgid: 694845).

Change-Id: I27cb95a4327ac42dd8bff5f64e98ade2e91b2730
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
src/crash-json2info/crash-json2info.c

index 083e37e..f864449 100644 (file)
@@ -57,6 +57,11 @@ static json_object *parse_json(FILE *fp)
                goto exit;
 
        buff = malloc(size);
+       if (!buff) {
+               printf("Memory allocation failed for JSON buffer %m\n");
+               goto exit;
+       }
+
        if (fread(buff, size, 1, fp) != 1) {
                printf("Cannot read the file: %d\n", ferror(fp));
                goto exit;