diff --git a/mysys/safemalloc.c b/mysys/safemalloc.c index 034b6f2536b..3d4988e29a4 100644 --- a/mysys/safemalloc.c +++ b/mysys/safemalloc.c @@ -66,7 +66,7 @@ struct st_irem uint32 marker; /* Underrun marker value */ }; -static int sf_malloc_count= 0; /* Number of allocated chunks */ +static uint sf_malloc_count= 0; /* Number of allocated chunks */ static void *sf_min_adress= (void*) (intptr)~0ULL, *sf_max_adress= 0; @@ -344,7 +344,7 @@ int sf_sanity() { struct st_irem *irem; int flag= 0; - int count= 0; + uint count= 0; pthread_mutex_lock(&sf_mutex); count= sf_malloc_count; @@ -369,6 +369,7 @@ void sf_report_leaked_memory(my_thread_id id) { size_t total= 0; struct st_irem *irem; + uint first= 0, chunks= 0; sf_sanity(); @@ -380,15 +381,18 @@ void sf_report_leaked_memory(my_thread_id id) { my_thread_id tid = irem->thread_id && irem->flags & MY_THREAD_SPECIFIC ? irem->thread_id : 0; + if (!first++) + fprintf(stderr, "Memory report from safemalloc\n"); fprintf(stderr, "Warning: %4lu bytes lost at %p, allocated by T@%llu at ", (ulong) irem->datasize, (char*) (irem + 1), tid); print_stack(irem->frame); total+= irem->datasize; + chunks++; } } if (total) - fprintf(stderr, "Memory lost: %lu bytes in %d chunks\n", - (ulong) total, sf_malloc_count); + fprintf(stderr, "Memory lost: %lu bytes in %u chunks of %u total chunks\n", + (ulong) total, chunks, sf_malloc_count); return; } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 7cca219dc81..d6ad9dc270b 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2480,6 +2480,8 @@ dispatch_end: */ thd->lex->m_sql_cmd= NULL; free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC)); + DBUG_EXECUTE_IF("print_allocated_thread_memory", + SAFEMALLOC_REPORT_MEMORY(sf_malloc_dbug_id());); #if defined(ENABLED_PROFILING) thd->profiling.finish_current_query(); diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 25ce43fd315..19c5f86c765 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1646,7 +1646,6 @@ int plugin_init(int *argc, char **argv, int flags) } } - free_root(&tmp_root, MYF(MY_MARK_BLOCKS_FREE)); tmp.state= PLUGIN_IS_UNINITIALIZED; if (register_builtin(plugin, &tmp, &plugin_ptr)) goto err_unlock;