Bug #54499 valgrind warnings for binlog.binlog_stm_do_db with custom patch
Submitted: 14 Jun 2010 20:54 Modified: 7 Nov 2015 8:23
Reporter: Mark Callaghan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB Plugin storage engine Severity:S3 (Non-critical)
Version:5.1.47 OS:Any
Assigned to: Assigned Account CPU Architecture:Any
Tags: Contribution, custom, innodb, plugin, valgrind

[14 Jun 2010 20:54] Mark Callaghan
Description:
We use MySQL 5.1.47 with the split page hash patch provided by you. That has a valgrind warning because table->heaps is allocated in ha_create but not freed. Allocation of it is new with the patch. The fix is:

--- a/storage/innodb_plugin/ha/hash0hash.c
+++ b/storage/innodb_plugin/ha/hash0hash.c
@@ -161,6 +161,13 @@ hash_table_free(
        ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);

        ut_free(table->array);
+
+       /* ha_create can allocate this */
+       if (table->heaps) {
+               mem_free(table->heaps);
+       }
+
        mem_free(table);
 }

How to repeat:
run mtr with innodb plugin
[14 Jun 2010 21:09] Mark Callaghan
I think this is a better patch for it

diff --git a/storage/innodb_plugin/ha/ha0ha.c b/storage/innodb_plugin/ha/ha0ha.c
index 1d69986..cfce55e 100644
--- a/storage/innodb_plugin/ha/ha0ha.c
+++ b/storage/innodb_plugin/ha/ha0ha.c
@@ -110,6 +110,16 @@ ha_clear(
        for (i = 0; i < n; i++) {
                mem_heap_free(table->heaps[i]);
        }
+
+       mem_free(table->heaps);
+       table->heaps = NULL;
+
+       for (i = 0; i < table->n_mutexes; i++) {
+               mutex_free(table->mutexes + i, sync_level);
+       }
+       mem_free(table->mutexes);
+       table->mutexes = NULL;
+
 #endif /* !UNIV_HOTBACKUP */
[14 Jun 2010 23:27] Mark Callaghan
The patch needs more patches. ha_clear cannot call mutex_free when called by buf_pool_close as sync_close has already been called. I added an argument (call_mutex_free)  to cover that.

#ifndef UNIV_HOTBACKUP
        /* Free the memory heaps. */
        n = table->n_mutexes;

        for (i = 0; i < n; i++) {
                mem_heap_free(table->heaps[i]);
        }

        mem_free(table->heaps);
        table->heaps = NULL;

        if (call_mutex_free) {
                /* When this is called by buf_pool_free it is too late to call
                mutex_free() */

                for (i = 0; i < table->n_mutexes; i++) {
                        mutex_free(table->mutexes + i);
                }
        }
        mem_free(table->mutexes);
        table->mutexes = NULL;

#endif /* !UNIV_HOTBACKUP */
[7 Nov 2015 8:23] MySQL Verification Team
ha_clear in 5.6.27 does free the memory.