qemu: fix dereference before null check 74/18674/2
authorKitae Kim <kt920.kim@samsung.com>
Fri, 28 Mar 2014 01:27:53 +0000 (10:27 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Fri, 28 Mar 2014 05:54:36 +0000 (14:54 +0900)
Change-Id: I750bf92f87ed2103f696ba3f8812075744941722
Signed-off-by: Kitae Kim <kt920.kim@samsung.com>
blockdev.c
tizen/src/maru_err_table.c

index 9a4a8fbde2c2226632cc4ab56923d1b4c6e67a60..84a48a0ebf04dcc97314d70a364b3e06b3eba6c1 100644 (file)
@@ -522,10 +522,11 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
     if (ret < 0) {
 #ifdef CONFIG_MARU
         const char _msg[] = "Failed to load disk file from the following path. Check if the file is corrupted or missing.\n\n";
-           char* err_msg = NULL;
+        char* err_msg = NULL;
+
         err_msg = maru_convert_path((char*)_msg, file);
-        start_simple_client(err_msg);
         if (err_msg) {
+            start_simple_client(err_msg);
             g_free(err_msg);
         }
 #endif
index 508a70ae3161c5632b227d99c2740ef431791ae7..29f55d699d90c661b0af52cabbf7a691c42eaabd 100644 (file)
@@ -166,6 +166,11 @@ char *maru_convert_path(char *msg, const char *path)
     total_len += (path_len + msg_len);
 
     err_msg = g_malloc0(total_len * sizeof(char));
+    if (!err_msg) {
+        fprintf(stderr, "failed to allocate a buffer for an error massage\n");
+        g_free(current_path);
+        return NULL;
+    }
 
     if (msg) {
         snprintf(err_msg, msg_len, "%s", msg);
@@ -188,9 +193,7 @@ char *maru_convert_path(char *msg, const char *path)
         if (!dos_err_msg) {
             fprintf(stderr,
                 "failed to duplicate an error message from %p\n", err_msg);
-            if (current_path) {
-                g_free(current_path);
-            }
+            g_free(current_path);
             g_free(err_msg);
             return NULL;
         }
@@ -204,9 +207,7 @@ char *maru_convert_path(char *msg, const char *path)
         g_free(dos_err_msg);
     }
 #endif
-    if (current_path) {
-        g_free(current_path);
-    }
+    g_free(current_path);
 
     return err_msg;
 }