From d914d09f58620937c20fa35279610d178d2ad03c Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Wed, 27 Sep 2023 13:55:39 +0200 Subject: [PATCH] MDEV-25329: Assertion `allocated_status_memory != __null' failed in void PROF_MEASUREMENT::set_label(const char*, const char*, const char*, unsigned int) Make profiler to play a bit better with memory allocators. Test suite can not be included because it lead to non free memory on shutdown (IMHO OK for memory shortage emulation) As alternetive all this should be rewritten and ability to return errors on upper level should be added. --- sql/sql_profile.cc | 7 ++++++- sql/sql_profile.h | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/sql/sql_profile.cc b/sql/sql_profile.cc index f36805012b2..d6c07d48a6b 100644 --- a/sql/sql_profile.cc +++ b/sql/sql_profile.cc @@ -203,7 +203,8 @@ void PROF_MEASUREMENT::set_label(const char *status_arg, sizes[2]= (file_arg == NULL) ? 0 : strlen(file_arg) + 1; allocated_status_memory= (char *) my_malloc(sizes[0] + sizes[1] + sizes[2], MYF(0)); - DBUG_ASSERT(allocated_status_memory != NULL); + if (!allocated_status_memory) + return; cursor= allocated_status_memory; @@ -267,6 +268,8 @@ QUERY_PROFILE::QUERY_PROFILE(PROFILING *profiling_arg, const char *status_arg) { m_seq_counter= 1; PROF_MEASUREMENT *prof= new PROF_MEASUREMENT(this, status_arg); + if (!prof) + return; prof->m_seq= m_seq_counter++; m_start_time_usecs= prof->time_usecs; m_end_time_usecs= m_start_time_usecs; @@ -308,6 +311,8 @@ void QUERY_PROFILE::new_status(const char *status_arg, prof= new PROF_MEASUREMENT(this, status_arg, function_arg, base_name(file_arg), line_arg); else prof= new PROF_MEASUREMENT(this, status_arg); + if (!prof) + DBUG_VOID_RETURN; prof->m_seq= m_seq_counter++; m_end_time_usecs= prof->time_usecs; diff --git a/sql/sql_profile.h b/sql/sql_profile.h index 5b03acf59c0..f618d059e2e 100644 --- a/sql/sql_profile.h +++ b/sql/sql_profile.h @@ -98,6 +98,8 @@ public: struct queue_item *new_item; new_item= (struct queue_item *) my_malloc(sizeof(struct queue_item), MYF(0)); + if (!new_item) + return; new_item->payload= payload; @@ -291,7 +293,11 @@ public: { DBUG_ASSERT(!current); if (unlikely(enabled)) - current= new QUERY_PROFILE(this, initial_state); + { + QUERY_PROFILE *new_profile= new QUERY_PROFILE(this, initial_state); + if (new_profile) + current= new_profile; + } } void discard_current_query();