fix double free when delete server mail
authorMinsoo Kim <minnsoo.kim@samsung.com>
Thu, 24 Jan 2013 06:10:20 +0000 (15:10 +0900)
committerMinsoo Kim <minnsoo.kim@samsung.com>
Thu, 24 Jan 2013 06:10:20 +0000 (15:10 +0900)
email-core/email-core-event.c
email-core/email-core-mail.c
email-core/email-storage/email-storage.c
email-daemon/email-daemon-account.c
email-daemon/email-daemon-mail.c
email-daemon/include/email-daemon.h
email-daemon/main.c
packaging/email-service.spec

index 9382b3f..d42c755 100755 (executable)
@@ -2393,7 +2393,7 @@ void* thread_func_branch_command(void *arg)
                                                }
                                                break;
 
-                                       case EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT:  {
+                                       case EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT: {
                                                        email_account_t *account = (email_account_t *)event_data.event_param_data_1;
                                                        event_handler_EMAIL_EVENT_VALIDATE_AND_UPDATE_ACCOUNT(event_data.account_id, account, handle_to_be_published, &err);
                                                        emcore_free_account(account);
index 351c6ee..7379f9f 100755 (executable)
@@ -649,7 +649,7 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv
        }
 
        for(i = 0; i < num; i++) {
-               if (!emstorage_get_downloaded_mail(mail_ids[i], &mail_tbl_data, false, &err) || !mail_tbl_data)  {
+               if (!emstorage_get_downloaded_mail(mail_ids[i], &mail_tbl_data, false, &err)) {
                        EM_DEBUG_EXCEPTION("emstorage_get_downloaded_mail failed [%d]", err);
 
                        if (err == EMAIL_ERROR_MAIL_NOT_FOUND) {        /* not server mail */
@@ -660,7 +660,12 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv
                }
        }
 
-       if (!emcore_connect_to_remote_mailbox(mail_tbl_data->account_id, mail_tbl_data->mailbox_id , (void **)&stream, &err))  {
+       if (!mail_tbl_data || mail_tbl_data->account_id <= 0 || mail_tbl_data->mailbox_id <= 0) {
+               EM_DEBUG_EXCEPTION("mail_tbl_data [%p]", mail_tbl_data);
+               goto FINISH_OFF;
+       }
+
+       if (!emcore_connect_to_remote_mailbox(mail_tbl_data->account_id, mail_tbl_data->mailbox_id , (void **)&stream, &err)) {
                EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
                goto FINISH_OFF;
        }
@@ -670,7 +675,7 @@ int emcore_delete_mails_from_imap4_server(int mail_ids[], int num, int from_serv
        /*  Here about 90 bytes are required for fixed keywords in the query-> SELECT local_uid, s_uid from mail_read_mail_uid_tbl where local_uid in (....) ORDER by s_uid  */
        /*  So length of comma separated strings which will be filled in (.....) in above query can be maximum QUERY_SIZE - 90  */
 
-       if (false == emcore_form_comma_separated_strings(mail_ids, num, QUERY_SIZE - 90, &string_list, &string_count, &err))   {
+       if (false == emcore_form_comma_separated_strings(mail_ids, num, QUERY_SIZE - 90, &string_list, &string_count, &err)) {
                EM_DEBUG_EXCEPTION("emcore_form_comma_separated_strings failed [%d]", err);
                goto FINISH_OFF;
        }
@@ -3444,7 +3449,6 @@ static int emcore_delete_mails_from_remote_server(int input_account_id, int inpu
        if (!emnetwork_check_network_status(&err)) {
                EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err);
                goto FINISH_OFF;
-
        }
 
        FINISH_OFF_IF_CANCELED;
@@ -3667,8 +3671,8 @@ INTERNAL_FUNC int emcore_delete_mails_from_local_storage(int account_id, int *ma
        }
 
        for(i = 0; i < num; i++) {
-               memset(mail_id_string, 0, 10);
-               SNPRINTF(mail_id_string, 10, "%d,", mail_ids[i]);
+               memset(mail_id_string, 0, sizeof(mail_id_string));
+               SNPRINTF(mail_id_string, sizeof(mail_id_string), "%d,", mail_ids[i]);
                strcat(noti_param_string, mail_id_string);
                /* can be optimized by appending sub string with directly pointing on string array kyuho.jo 2011-10-07 */
        }
@@ -3702,13 +3706,11 @@ INTERNAL_FUNC int emcore_delete_mails_from_local_storage(int account_id, int *ma
                /*  delete mail contents from filesystem */
                if (!emstorage_get_save_name(account_id, result_mail_list[i].mail_id, 0, NULL, buf, &err)) {
                        EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err);
-
                        goto FINISH_OFF;
                }
 
                if (!emstorage_delete_dir(buf, &err)) {
                        EM_DEBUG_EXCEPTION("emstorage_delete_dir failed [%d]", err);
-
                }
                
                /* Deleting Meeting Request */
index 0d7ab76..85bce46 100755 (executable)
@@ -5371,7 +5371,7 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, ch
        
        if(rc != SQLITE_ROW && rc != SQLITE_DONE) {
                EM_DEBUG_EXCEPTION("sqlite3_step fail:%d", rc);
-                       error = EMAIL_ERROR_DB_FAILURE;
+               error = EMAIL_ERROR_DB_FAILURE;
                goto FINISH_OFF; 
        }
        
@@ -5394,7 +5394,7 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, ch
                error = EMAIL_ERROR_DB_FAILURE;
                goto FINISH_OFF; 
        }
-
+       
        _bind_stmt_field_data_int(hStmt_mail_tbl, i++, new_mailbox_type);
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt_mail_tbl), rc);
@@ -5933,8 +5933,8 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail(int mail_id, emstorage_mail_tbl_
 {
        EM_DEBUG_FUNC_BEGIN("mail_id[%d], mail[%p], err_code[%p]", mail_id, mail, err_code);
 
-       if (!mail {
-               EM_DEBUG_EXCEPTION(" mail_id[%d], mail[%p]", mail_id, mail);
+       if (!mail || mail_id <= 0) {
+               EM_DEBUG_EXCEPTION("mail_id[%d], mail[%p]", mail_id, mail);
                if (err_code != NULL)
                        *err_code = EMAIL_ERROR_INVALID_PARAM;
                return false;
@@ -7271,7 +7271,6 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i
 {
        EM_DEBUG_FUNC_BEGIN("mail_ids[%p], number_of_mails [%d], type[%d], mail[%p], transaction[%d], err_code[%p]", mail_ids, number_of_mails, type, mail, transaction, err_code);
 
-       DB_STMT hStmt = NULL;
        int ret = false;
        int error = EMAIL_ERROR_NONE;
        int query_string_length = 0;
@@ -7346,8 +7345,11 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i
        EM_DEBUG_LOG("Query [%s], Length [%d]", sql_query_string, EM_SAFE_STRLEN(sql_query_string));
 
        EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &item_count, 0, NULL), rc);
-       EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
-               ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+       if (SQLITE_OK != rc && -1 != rc) {
+               EM_DEBUG_EXCEPTION("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle));
+               error = EMAIL_ERROR_DB_FAILURE;
+               goto FINISH_OFF;
+       }
 
        if (rc == SQLITE_DONE)  {
                EM_DEBUG_EXCEPTION("no matched mail found...");
@@ -7404,25 +7406,16 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(int mail_ids[], i
                }
        }
 
-       sqlite3_free_table(result);
-
        ret = true;
 
 FINISH_OFF:
        if (ret == true)
                *mail = p_data_tbl;
-       else if (p_data_tbl != NULL)
-               emstorage_free_mail(&p_data_tbl,  1, NULL);
-
-       if (hStmt != NULL) {
-               EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
+       else
+               emstorage_free_mail(&p_data_tbl, number_of_mails, NULL);
 
-               rc = sqlite3_finalize(hStmt);
-               if (rc != SQLITE_OK) {
-                       EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
-                       error = EMAIL_ERROR_DB_FAILURE;
-               }
-       }
+       if (result)
+               sqlite3_free_table(result);
 
        EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
        _DISCONNECT_DB;
@@ -10267,13 +10260,13 @@ INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_
        }
 
        sprintf(name_buf, "%s", MAILHOME);
-       sprintf(name_buf+EM_SAFE_STRLEN(name_buf),      "%s%d", DIR_SEPERATOR, account_id);
+       sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, account_id);
 
        if (mail_id > 0)
-               sprintf(name_buf+EM_SAFE_STRLEN(name_buf),      "%s%d", DIR_SEPERATOR, mail_id);
+               sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, mail_id);
 
        if (atch_id > 0)
-               sprintf(name_buf+EM_SAFE_STRLEN(name_buf),      "%s%d", DIR_SEPERATOR, atch_id);
+               sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, atch_id);
 
        if (fname) {
                temp_file = EM_SAFE_STRDUP(fname);
@@ -10283,19 +10276,17 @@ INTERNAL_FUNC int emstorage_get_save_name(int account_id, int mail_id, int atch_
        }
 
        if (dir_name) {
-               sprintf(create_dir,     "%s%s%s", name_buf, DIR_SEPERATOR, dir_name);
+               sprintf(create_dir, "%s%s%s", name_buf, DIR_SEPERATOR, dir_name);
                EM_DEBUG_LOG(">>>>> DIR PATH [ %s ]", create_dir);
                mkdir(create_dir, DIRECTORY_PERMISSION);
                EM_SAFE_FREE(temp_file);
        }
 
-
        if (fname) {
                EM_DEBUG_LOG(">>>>> fname [ %s ]", fname);
-               sprintf(name_buf+EM_SAFE_STRLEN(name_buf),      "%s%s", DIR_SEPERATOR, fname);
+               sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%s", DIR_SEPERATOR, fname);
        }
 
-
        EM_DEBUG_LOG(">>>>> name_buf [ %s ]", name_buf);
 
        ret = true;
@@ -10853,7 +10844,7 @@ INTERNAL_FUNC int emstorage_delete_dir(char *src_dir, int *err_code)
        EM_DEBUG_FUNC_BEGIN("src_dir[%p], err_code[%p]", src_dir, err_code);
 
        if (src_dir == NULL) {
-               EM_DEBUG_EXCEPTION(" src_dir[%p]", src_dir);
+               EM_DEBUG_EXCEPTION("src_dir[%p]", src_dir);
 
                if (err_code != NULL)
                        *err_code = EMAIL_ERROR_INVALID_PARAM;
@@ -13483,7 +13474,7 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(int account_id, int thread
        int rc = -1, ret = false;
        int err = EMAIL_ERROR_NONE;
        char sql_query_string[QUERY_SIZE] = {0, };
-       char **result;
+       char **result = NULL;
        int result_count = 0;
 
        if (thread_id == 0) {
index b88791f..587d884 100755 (executable)
@@ -549,12 +549,12 @@ FINISH_OFF:
        return ret;
 }
 
-INTERNAL_FUNC int emdaemon_add_filter(email_rule_t* filter_info, int* err_code)
+INTERNAL_FUNC int emdaemon_add_filter(email_rule_t* filter_info)
 {
-       EM_DEBUG_FUNC_BEGIN("filter_info[%p], err_code[%p]", filter_info, err_code);
+       EM_DEBUG_FUNC_BEGIN("filter_info[%p]", filter_info);
 
        /*  default variable */
-       int ret = false, err = EMAIL_ERROR_NONE;
+       int err = EMAIL_ERROR_NONE;
        if (!filter_info || !(filter_info->value))  {
                EM_DEBUG_EXCEPTION("filter_info[%p]", filter_info);
                err = EMAIL_ERROR_INVALID_PARAM;
@@ -588,19 +588,20 @@ INTERNAL_FUNC int emdaemon_add_filter(email_rule_t* filter_info, int* err_code)
                goto FINISH_OFF;
        }
 
+       if (filter_info->type == EMAIL_PRIORITY_SENDER) {
+               EM_DEBUG_LOG("Priority Sender add");
+               goto FINISH_OFF;
+       }
+
        if (!emcore_mail_filter_by_rule((email_rule_t*)filter_info, &err))  {
                EM_DEBUG_EXCEPTION("emcore_mail_filter_by_rule failed [%d]", err);
                goto FINISH_OFF;
        }
 
-       ret = true;
-
 FINISH_OFF:
 
-       if (err_code)
-               *err_code = err;
        EM_DEBUG_FUNC_END();
-       return ret;
+       return err;
 }
 
 INTERNAL_FUNC int emdaemon_update_filter(int filter_id, email_rule_t* filter_info, int* err_code)
index ba0b9d2..1deb058 100755 (executable)
@@ -535,8 +535,11 @@ void* thread_func_to_delete_mail(void *thread_argument)
        }
 
 FINISH_OFF:
-       /* emcore_free_event(event_data); */ /* all of members will be freed after using in each event handler */
-       EM_SAFE_FREE(event_data->event_param_data_3); /*prevent 33692*/
+       /* all of members will be freed after using in each event handler */
+
+       if (from_server != EMAIL_DELETE_LOCAL_AND_SERVER && from_server != EMAIL_DELETE_FROM_SERVER) {
+               EM_SAFE_FREE(event_data->event_param_data_3);
+       }
        EM_SAFE_FREE(event_data);
 
        EM_DEBUG_FUNC_END();
@@ -549,7 +552,8 @@ INTERNAL_FUNC int emdaemon_delete_mail(int mailbox_id, int mail_ids[], int mail_
 
        int ret = false;
        int err = EMAIL_ERROR_NONE;
-       int* p = NULL, thread_error;
+       int *p = NULL;
+       int thread_error = 0;
        email_account_t *ref_account = NULL;
        email_event_t *event_data = NULL;
        emstorage_mailbox_tbl_t *mailbox_tbl_data = NULL;
@@ -613,8 +617,10 @@ FINISH_OFF:
                EM_SAFE_FREE(ref_account);
        }
 
-       if (ret == false)
+       if (thread_error != 0) {
+               EM_SAFE_FREE(event_data);
                EM_SAFE_FREE(p);
+       }
 
        if (err_code)
                *err_code = err;
index 0decfb2..39de525 100755 (executable)
@@ -200,11 +200,10 @@ INTERNAL_FUNC int emdaemon_find_filter(email_rule_t* filter_info, int* err_code)
  * Add a filter information.
  *
  * @param[in] filtering_set            Specifies the pointer of adding filter structure.
- * @param[out] err_code                Specifies the error code returned.
  * @remarks N/A
  * @return This function returns true on success or false on failure.(only EMAIL_FILTER_BLOCK supported.)
  */
-INTERNAL_FUNC int emdaemon_add_filter(email_rule_t* filtering_set, int* err_code);
+INTERNAL_FUNC int emdaemon_add_filter(email_rule_t* filtering_set);
 
 /**
  * Change a filter information.
index 24c1516..836c1b3 100755 (executable)
@@ -826,7 +826,7 @@ void stb_add_rule(HIPC_API a_hAPI)
        EM_DEBUG_LOG("account ID  [%d]", rule.account_id);
 
        /* call add_filter handler */
-       emdaemon_add_filter(&rule, &err);
+       err = emdaemon_add_filter(&rule);
 
 FINISH_OFF:
        if(!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
index 603e5ca..4e4f537 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       email-service
 Summary:    E-mail Framework Middleware package
-Version:    0.10.81
+Version:    0.10.82
 Release:    1
 Group:      System/Libraries
 License:    TBD
@@ -107,7 +107,7 @@ vconftool set -t int    db/badge/com.samsung.email "0" -g 6514
 vconftool set -t int    memory/sync/email "0" -i -g 6514
 
 # for priority send 
-vconftool set -t string db/private/email-service/noti_ringthone_path "Whistle.mp3" -g 6514
+vconftool set -t string db/private/email-service/noti_ringtone_path "Whistle.mp3" -g 6514
 vconftool set -t int    db/private/email-service/noti_rep_type "0" -g 6514
 vconftool set -t bool   db/private/email-service/noti_notification_ticker "0" -g 6514
 vconftool set -t bool   db/private/email-service/noti_display_content_ticker "0" -g 6514