Fix NULL dereference issue and uninitialized variable issue
[platform/core/connectivity/bluetooth-agent.git] / map-agent / bluetooth_map_email.c
index 03c0ea2..0709816 100644 (file)
@@ -744,6 +744,12 @@ static char *__bt_prepare_email_bmseg(email_mail_data_t *mail_data)
        if (body_file != NULL) {
                fseek(body_file, 0, SEEK_END);
                email_size = ftell(body_file);
+               if (email_size <= 0) {
+                       ERR("email_size is not a positive number");
+                       g_string_free(msg, TRUE);
+                       fclose(body_file);
+                       return NULL;
+               }
                rewind(body_file);
 
                buf = (char *)g_malloc0(sizeof(char) * email_size);
@@ -752,7 +758,6 @@ static char *__bt_prepare_email_bmseg(email_mail_data_t *mail_data)
                DBG("MESSAGE: [%s]", buf);
                if (read_size != email_size) {
                        ERR("Unequal Read size");
-                       email_free_mail_data(&mail_data, 1);
                        g_string_free(msg, TRUE);
                        g_free(buf);
                        return NULL;