diff --git a/storage/tianchi/datatype_cnvrtr.cc b/storage/tianchi/datatype_cnvrtr.cc index f1ec7a54de485ea4488ee97bc460430a673f4fb1..2a91584d72b2fb5d621509c82ccee5ffc6d35503 100644 --- a/storage/tianchi/datatype_cnvrtr.cc +++ b/storage/tianchi/datatype_cnvrtr.cc @@ -466,6 +466,7 @@ int convert_blob_to_cantian(uchar *cantian_ptr, uint32 &cantian_offset, if (lob_locator == nullptr) { tse_log_error("[mysql2cantian]Apply for lob locator:%u Failed", locator_size); my_error(ER_OUT_OF_RESOURCES, MYF(0), "LOB LOCATOR"); + my_free(lob_locator); field_len = 0; return HA_ERR_SE_OUT_OF_MEMORY; } @@ -549,6 +550,7 @@ void convert_blob_to_mysql(uchar *cantian_ptr, Field *mysql_field, tianchi_handl if (blob_buf == nullptr) { tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", blob_len); my_error(ER_OUT_OF_RESOURCES, MYF(0), "BLOB DATA"); + my_free(blob_buf); return; } @@ -1586,6 +1588,12 @@ void copy_column_data_to_mysql(field_info_t *field_info, const field_cnvrt_aux_t if (is_index_only) { uint32_t blob_len = field_info->field_len; char *blob_buf = (char *)my_malloc(PSI_NOT_INSTRUMENTED, blob_len * sizeof(char), MYF(MY_WME)); + if (blob_buf == nullptr) { + tse_log_error("[cantian2mysql]Apply for blob buf:%u Failed", blob_len); + my_error(ER_OUT_OF_RESOURCES, MYF(0), "BLOB DATA"); + my_free(blob_buf); + return; + } memcpy(blob_buf, field_info->cantian_cur_field, blob_len); memcpy(field_info->mysql_cur_field, &blob_buf, sizeof(char *)); bitmap_set_bit(field_info->field->table->read_set, field_info->field->field_index()); diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index a6f13bdc7ad836796e1b065db3f3dc9c68c3c1eb..8608f2ddfd4ddf129a5964d4eafd984e0a8620ee 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -1228,6 +1228,7 @@ thd_sess_ctx_s *get_or_init_sess_ctx(handlerton *hton, THD *thd) { sess_ctx = (thd_sess_ctx_s *)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(thd_sess_ctx_s), MYF(MY_WME)); if (sess_ctx == nullptr) { + my_free(sess_ctx); return nullptr; } @@ -2117,6 +2118,7 @@ int ha_tse::prefetch_and_fill_record_buffer(uchar *buf, tse_prefetch_fn prefetch } if (m_prefetch_buf == nullptr) { tse_log_error("alloc mem failed, m_prefetch_buf size(%u)", MAX_RECORD_SIZE); + my_free(m_prefetch_buf); return HA_ERR_OUT_OF_MEM; } @@ -2640,6 +2642,11 @@ void ha_tse::start_bulk_insert(ha_rows rows) { if (m_rec_buf_data == nullptr) { m_rec_buf_data = (uchar *)my_malloc(PSI_NOT_INSTRUMENTED, MAX_RECORD_BUFFER_SIZE_TSE, MYF(MY_WME)); } + if (m_rec_buf_data == nullptr) { + tse_log_error("alloc mem failed, m_prefetch_buf size(%u)", MAX_RECORD_BUFFER_SIZE_TSE); + my_free(m_rec_buf_data); + return; + } if (rows == 1 || m_is_insert_dup || m_is_replace || m_ignore_dup || table->s->blob_fields > 0 || table->next_number_field || m_rec_buf_data == nullptr) { @@ -2862,6 +2869,7 @@ int ha_tse::set_prefetch_buffer() { } if (m_rec_buf_data == nullptr) { tse_log_error("alloc mem failed, m_rec_buf_data size(%u)", MAX_RECORD_BUFFER_SIZE_TSE); + my_free(m_rec_buf_data); return ERR_ALLOC_MEMORY; } @@ -5237,21 +5245,36 @@ int ha_tse::initialize_cbo_stats() m_share->cbo_stats = (tianchi_cbo_stats_t*)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(tianchi_cbo_stats_t), MYF(MY_WME)); if (m_share->cbo_stats == nullptr) { tse_log_error("alloc shm mem failed, m_share->cbo_stats size(%lu)", sizeof(tianchi_cbo_stats_t)); + my_free(m_share->cbo_stats); return ERR_ALLOC_MEMORY; } *m_share->cbo_stats = {0, 0, 0, 0, 0, nullptr, nullptr}; m_share->cbo_stats->tse_cbo_stats_table = (tse_cbo_stats_table_t*)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(tse_cbo_stats_table_t), MYF(MY_WME)); + if (m_share->cbo_stats->tse_cbo_stats_table == nullptr) { + tse_log_error("alloc shm mem failed, m_share->cbo_stats size(%lu)", sizeof(tse_cbo_stats_table_t)); + my_free(m_share->cbo_stats->tse_cbo_stats_table); + return ERR_ALLOC_MEMORY; + } m_share->cbo_stats->tse_cbo_stats_table->columns = (tse_cbo_stats_column_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->fields * sizeof(tse_cbo_stats_column_t), MYF(MY_WME)); THD* thd = ha_thd(); + if (m_share->cbo_stats->tse_cbo_stats_table->columns == nullptr) { + tse_log_error("alloc shm mem failed, m_share->cbo_stats size(%lu)", table->s->fields * sizeof(tse_cbo_stats_column_t)); + my_free(m_share->cbo_stats->tse_cbo_stats_table->columns); + return ERR_ALLOC_MEMORY; + } if (user_var_set(thd, "ctc_show_alloc_cbo_stats_mem")) { tse_log_system("[alloc memory]normal table : %s alloc size :%lu", table->alias, calculate_size_of_cbo_stats(table)); } m_share->cbo_stats->ndv_keys = (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t), MYF(MY_WME)); - + if (m_share->cbo_stats->ndv_keys == nullptr) { + tse_log_error("alloc shm mem failed, m_share->cbo_stats size(%lu)", table->s->keys * sizeof(uint32_t)); + my_free(m_share->cbo_stats->ndv_keys); + return ERR_ALLOC_MEMORY; + } m_share->cbo_stats->msg_len = table->s->fields * sizeof(tse_cbo_stats_column_t); m_share->cbo_stats->key_len = table->s->keys * sizeof(uint32_t); return CT_SUCCESS; diff --git a/storage/tianchi/ha_tsepart.cc b/storage/tianchi/ha_tsepart.cc index e2103cb6ae1ecf0c2bdafd9c24fc01245d6a81fd..58e6224c59446d67f5915e9ce447cb74860c482e 100644 --- a/storage/tianchi/ha_tsepart.cc +++ b/storage/tianchi/ha_tsepart.cc @@ -84,7 +84,7 @@ static bool get_used_partitions(partition_info *part_info, *subpart_ids = (uint32_t *)my_malloc(PSI_NOT_INSTRUMENTED, (*used_parts) * sizeof(uint32_t), MYF(MY_WME)); if (*subpart_ids == NULL) { tse_log_system("Failed to allocate memory for subpart_ids. Freeing previously allocated memory..."); - my_free(*part_ids); + my_free(*subpart_ids); return false; } uint32_t part_id = part_info->get_first_used_partition(); @@ -284,6 +284,10 @@ void ha_tsepart::start_bulk_insert(ha_rows rows) { // m_max_batch_num is fixed after open table, if table structrue is changed, it should be closed and reopened m_bulk_insert_parts = (ctc_part_t *)my_malloc(PSI_NOT_INSTRUMENTED, m_max_batch_num * sizeof(ctc_part_t), MYF(MY_WME)); + if (m_bulk_insert_parts == nullptr) { + tse_log_error("[cantian2mysql]Apply for blob buf:%lu Failed", m_max_batch_num * sizeof(ctc_part_t)); + my_free(m_bulk_insert_parts); + } } } } @@ -1009,6 +1013,7 @@ int ha_tsepart::initialize_cbo_stats() { m_part_share->cbo_stats = (tianchi_cbo_stats_t*)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(tianchi_cbo_stats_t), MYF(MY_WME)); if (m_part_share->cbo_stats == nullptr) { tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", sizeof(tianchi_cbo_stats_t)); + my_free(m_part_share->cbo_stats); return ERR_ALLOC_MEMORY; } *m_part_share->cbo_stats = {0, 0, 0, 0, 0, nullptr, nullptr}; @@ -1017,11 +1022,26 @@ int ha_tsepart::initialize_cbo_stats() { m_part_share->cbo_stats->tse_cbo_stats_table = (tse_cbo_stats_table_t*)my_malloc(PSI_NOT_INSTRUMENTED, part_num * sizeof(tse_cbo_stats_table_t), MYF(MY_WME)); + if (m_part_share->cbo_stats->tse_cbo_stats_table == nullptr) { + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", part_num * sizeof(tse_cbo_stats_table_t)); + my_free(m_part_share->cbo_stats->tse_cbo_stats_table); + return ERR_ALLOC_MEMORY; + } m_part_share->cbo_stats->ndv_keys = (uint32_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->keys * sizeof(uint32_t), MYF(MY_WME)); + if (m_part_share->cbo_stats->ndv_keys == nullptr) { + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", table->s->keys * sizeof(uint32_t)); + my_free(m_part_share->cbo_stats->ndv_keys); + return ERR_ALLOC_MEMORY; + } for (uint i = 0; i < part_num; i++) { m_part_share->cbo_stats->tse_cbo_stats_table[i].columns = (tse_cbo_stats_column_t*)my_malloc(PSI_NOT_INSTRUMENTED, table->s->fields * sizeof(tse_cbo_stats_column_t), MYF(MY_WME)); + if (m_part_share->cbo_stats->tse_cbo_stats_table[i].columns == nullptr) { + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", table->s->fields * sizeof(tse_cbo_stats_column_t)); + my_free(m_part_share->cbo_stats->tse_cbo_stats_table[i].columns); + return ERR_ALLOC_MEMORY; + } } m_part_share->cbo_stats->msg_len = table->s->fields * sizeof(tse_cbo_stats_column_t); m_part_share->cbo_stats->key_len = table->s->keys * sizeof(uint32_t); diff --git a/storage/tianchi/mysql_daac_plugin.cc b/storage/tianchi/mysql_daac_plugin.cc index 91c6b10c0d77b010c3ce3461843b35d2e504c3d3..4d2bde81b716749a97b29ddcb83d4c9648633662 100644 --- a/storage/tianchi/mysql_daac_plugin.cc +++ b/storage/tianchi/mysql_daac_plugin.cc @@ -119,6 +119,11 @@ int daemon_daac_plugin_init() { daac_context = (struct mysql_daac_context *)my_malloc( PSI_NOT_INSTRUMENTED, sizeof(struct mysql_daac_context), MYF(0)); + if (daac_context == nullptr) { + tse_log_error("alloc shm mem failed, m_part_share->cbo_stats size(%lu)", sizeof(struct mysql_daac_context)); + my_free(daac_context); + return ERR_ALLOC_MEMORY; + } my_thread_attr_t startup_attr; /* Thread attributes */ my_thread_attr_init(&startup_attr);