Commit 5eb3e4d8 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-15798 Mutex leak on accessing INFORMATION_SCHEMA.INNODB_MUTEXES

i_s_innodb_mutexes_fill_table(): Use the C++ RAII pattern
to ensure that the mutexes are released if an OK()
macro returns from the function prematurely.
parent 4c490d6d
/*****************************************************************************
Copyright (c) 2007, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2014, 2018, MariaDB Corporation.
Copyright (c) 2014, 2019, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
......@@ -8819,7 +8819,12 @@ i_s_innodb_mutexes_fill_table(
DBUG_RETURN(0);
}
mutex_enter(&mutex_list_mutex);
{
struct Locking
{
Locking() { mutex_enter(&mutex_list_mutex); }
~Locking() { mutex_exit(&mutex_list_mutex); }
} locking;
for (mutex = UT_LIST_GET_FIRST(mutex_list); mutex != NULL;
mutex = UT_LIST_GET_NEXT(list, mutex)) {
......@@ -8829,14 +8834,20 @@ i_s_innodb_mutexes_fill_table(
if (buf_pool_is_block_mutex(mutex)) {
block_mutex = mutex;
block_mutex_oswait_count += mutex->count_os_wait;
block_mutex_oswait_count
+= mutex->count_os_wait;
continue;
}
OK(field_store_string(fields[MUTEXES_NAME], mutex->cmutex_name));
OK(field_store_string(fields[MUTEXES_CREATE_FILE], innobase_basename(mutex->cfile_name)));
OK(field_store_ulint(fields[MUTEXES_CREATE_LINE], mutex->cline));
OK(field_store_ulint(fields[MUTEXES_OS_WAITS], (longlong)mutex->count_os_wait));
OK(field_store_string(fields[MUTEXES_NAME],
mutex->cmutex_name));
OK(field_store_string(
fields[MUTEXES_CREATE_FILE],
innobase_basename(mutex->cfile_name)));
OK(field_store_ulint(fields[MUTEXES_CREATE_LINE],
mutex->cline));
OK(field_store_ulint(fields[MUTEXES_OS_WAITS],
mutex->count_os_wait));
OK(schema_table_store_record(thd, tables->table));
}
......@@ -8846,16 +8857,24 @@ i_s_innodb_mutexes_fill_table(
my_snprintf(buf1, sizeof buf1, "combined %s",
innobase_basename(block_mutex->cfile_name));
OK(field_store_string(fields[MUTEXES_NAME], block_mutex->cmutex_name));
OK(field_store_string(fields[MUTEXES_CREATE_FILE], buf1));
OK(field_store_ulint(fields[MUTEXES_CREATE_LINE], block_mutex->cline));
OK(field_store_ulint(fields[MUTEXES_OS_WAITS], (longlong)block_mutex_oswait_count));
OK(field_store_string(fields[MUTEXES_NAME],
block_mutex->cmutex_name));
OK(field_store_string(fields[MUTEXES_CREATE_FILE],
buf1));
OK(field_store_ulint(fields[MUTEXES_CREATE_LINE],
block_mutex->cline));
OK(field_store_ulint(fields[MUTEXES_OS_WAITS],
block_mutex_oswait_count));
OK(schema_table_store_record(thd, tables->table));
}
}
mutex_exit(&mutex_list_mutex);
mutex_enter(&rw_lock_list_mutex);
{
struct Locking
{
Locking() { mutex_enter(&rw_lock_list_mutex); }
~Locking() { mutex_exit(&rw_lock_list_mutex); }
} locking;
for (lock = UT_LIST_GET_FIRST(rw_lock_list); lock != NULL;
lock = UT_LIST_GET_NEXT(list, lock)) {
......@@ -8869,10 +8888,15 @@ i_s_innodb_mutexes_fill_table(
continue;
}
OK(field_store_string(fields[MUTEXES_NAME], lock->lock_name));
OK(field_store_string(fields[MUTEXES_CREATE_FILE], innobase_basename(lock->cfile_name)));
OK(field_store_ulint(fields[MUTEXES_CREATE_LINE], lock->cline));
OK(field_store_ulint(fields[MUTEXES_OS_WAITS], (longlong)lock->count_os_wait));
OK(field_store_string(fields[MUTEXES_NAME],
lock->lock_name));
OK(field_store_string(
fields[MUTEXES_CREATE_FILE],
innobase_basename(lock->cfile_name)));
OK(field_store_ulint(fields[MUTEXES_CREATE_LINE],
lock->cline));
OK(field_store_ulint(fields[MUTEXES_OS_WAITS],
lock->count_os_wait));
OK(schema_table_store_record(thd, tables->table));
}
......@@ -8882,14 +8906,17 @@ i_s_innodb_mutexes_fill_table(
my_snprintf(buf1, sizeof buf1, "combined %s",
innobase_basename(block_lock->cfile_name));
OK(field_store_string(fields[MUTEXES_NAME], block_lock->lock_name));
OK(field_store_string(fields[MUTEXES_CREATE_FILE], buf1));
OK(field_store_ulint(fields[MUTEXES_CREATE_LINE], block_lock->cline));
OK(field_store_ulint(fields[MUTEXES_OS_WAITS], (longlong)block_lock_oswait_count));
OK(field_store_string(fields[MUTEXES_NAME],
block_lock->lock_name));
OK(field_store_string(fields[MUTEXES_CREATE_FILE],
buf1));
OK(field_store_ulint(fields[MUTEXES_CREATE_LINE],
block_lock->cline));
OK(field_store_ulint(fields[MUTEXES_OS_WAITS],
block_lock_oswait_count));
OK(schema_table_store_record(thd, tables->table));
}
mutex_exit(&rw_lock_list_mutex);
}
DBUG_RETURN(0);
}
......
/*****************************************************************************
Copyright (c) 2007, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2014, 2018, MariaDB Corporation.
Copyright (c) 2014, 2019, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
......@@ -9120,7 +9120,12 @@ i_s_innodb_mutexes_fill_table(
DBUG_RETURN(0);
}
mutex_enter(&mutex_list_mutex);
{
struct Locking
{
Locking() { mutex_enter(&mutex_list_mutex); }
~Locking() { mutex_exit(&mutex_list_mutex); }
} locking;
for (mutex = UT_LIST_GET_FIRST(mutex_list); mutex != NULL;
mutex = UT_LIST_GET_NEXT(list, mutex)) {
......@@ -9130,14 +9135,20 @@ i_s_innodb_mutexes_fill_table(
if (buf_pool_is_block_mutex(mutex)) {
block_mutex = mutex;
block_mutex_oswait_count += mutex->count_os_wait;
block_mutex_oswait_count
+= mutex->count_os_wait;
continue;
}
OK(field_store_string(fields[MUTEXES_NAME], mutex->cmutex_name));
OK(field_store_string(fields[MUTEXES_CREATE_FILE], innobase_basename(mutex->cfile_name)));
OK(field_store_ulint(fields[MUTEXES_CREATE_LINE], mutex->cline));
OK(field_store_ulint(fields[MUTEXES_OS_WAITS], (longlong)mutex->count_os_wait));
OK(field_store_string(fields[MUTEXES_NAME],
mutex->cmutex_name));
OK(field_store_string(
fields[MUTEXES_CREATE_FILE],
innobase_basename(mutex->cfile_name)));
OK(field_store_ulint(fields[MUTEXES_CREATE_LINE],
mutex->cline));
OK(field_store_ulint(fields[MUTEXES_OS_WAITS],
mutex->count_os_wait));
OK(schema_table_store_record(thd, tables->table));
}
......@@ -9147,16 +9158,24 @@ i_s_innodb_mutexes_fill_table(
my_snprintf(buf1, sizeof buf1, "combined %s",
innobase_basename(block_mutex->cfile_name));
OK(field_store_string(fields[MUTEXES_NAME], block_mutex->cmutex_name));
OK(field_store_string(fields[MUTEXES_CREATE_FILE], buf1));
OK(field_store_ulint(fields[MUTEXES_CREATE_LINE], block_mutex->cline));
OK(field_store_ulint(fields[MUTEXES_OS_WAITS], (longlong)block_mutex_oswait_count));
OK(field_store_string(fields[MUTEXES_NAME],
block_mutex->cmutex_name));
OK(field_store_string(fields[MUTEXES_CREATE_FILE],
buf1));
OK(field_store_ulint(fields[MUTEXES_CREATE_LINE],
block_mutex->cline));
OK(field_store_ulint(fields[MUTEXES_OS_WAITS],
block_mutex_oswait_count));
OK(schema_table_store_record(thd, tables->table));
}
}
mutex_exit(&mutex_list_mutex);
mutex_enter(&rw_lock_list_mutex);
{
struct Locking
{
Locking() { mutex_enter(&rw_lock_list_mutex); }
~Locking() { mutex_exit(&rw_lock_list_mutex); }
} locking;
for (lock = UT_LIST_GET_FIRST(rw_lock_list); lock != NULL;
lock = UT_LIST_GET_NEXT(list, lock)) {
......@@ -9170,10 +9189,15 @@ i_s_innodb_mutexes_fill_table(
continue;
}
OK(field_store_string(fields[MUTEXES_NAME], lock->lock_name));
OK(field_store_string(fields[MUTEXES_CREATE_FILE], innobase_basename(lock->cfile_name)));
OK(field_store_ulint(fields[MUTEXES_CREATE_LINE], lock->cline));
OK(field_store_ulint(fields[MUTEXES_OS_WAITS], (longlong)lock->count_os_wait));
OK(field_store_string(fields[MUTEXES_NAME],
lock->lock_name));
OK(field_store_string(
fields[MUTEXES_CREATE_FILE],
innobase_basename(lock->cfile_name)));
OK(field_store_ulint(fields[MUTEXES_CREATE_LINE],
lock->cline));
OK(field_store_ulint(fields[MUTEXES_OS_WAITS],
lock->count_os_wait));
OK(schema_table_store_record(thd, tables->table));
}
......@@ -9183,14 +9207,17 @@ i_s_innodb_mutexes_fill_table(
my_snprintf(buf1, sizeof buf1, "combined %s",
innobase_basename(block_lock->cfile_name));
OK(field_store_string(fields[MUTEXES_NAME], block_lock->lock_name));
OK(field_store_string(fields[MUTEXES_CREATE_FILE], buf1));
OK(field_store_ulint(fields[MUTEXES_CREATE_LINE], block_lock->cline));
OK(field_store_ulint(fields[MUTEXES_OS_WAITS], (longlong)block_lock_oswait_count));
OK(field_store_string(fields[MUTEXES_NAME],
block_lock->lock_name));
OK(field_store_string(fields[MUTEXES_CREATE_FILE],
buf1));
OK(field_store_ulint(fields[MUTEXES_CREATE_LINE],
block_lock->cline));
OK(field_store_ulint(fields[MUTEXES_OS_WAITS],
block_lock_oswait_count));
OK(schema_table_store_record(thd, tables->table));
}
mutex_exit(&rw_lock_list_mutex);
}
DBUG_RETURN(0);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment