Bug #67983 Memory leak on filtered slave
Submitted: 28 Dec 2012 16:39 Modified: 31 Jan 2013 9:00
Reporter: Sergei Glushchenko Email Updates:
Status: Closed Impact on me:
Category:MySQL Server: Replication Severity:S1 (Critical)
Version:5.5.25a OS:Any
Assigned to: CPU Architecture:Any
Tags: deferred events, filtered slave, memory leak, replication

[28 Dec 2012 16:39] Sergei Glushchenko
Due to incorrect management of deferred events there is a memory leak on filtered slaves. Pseudo random sequence of relay log events is not deleted. last_added pointer is not updated correctly in Deferred_log_events::rewind. It points to free memory region after container cleared. This leads to memory leak in following lines:

    if (ev->get_type_code() != FORMAT_DESCRIPTION_EVENT &&
      DBUG_PRINT("info", ("Deleting the event after it has been executed"));
      delete ev;

because is_deferred_event implemented as following:

  bool is_deferred_event(Log_event * ev)
    return deferred_events_collecting ? deferred_events->is_last(ev) : false;


bool is_last(Log_event *ev) { return ev == last_added; };

So if memory region allocated for subsequent event has same address which last_added points to, such event will not be added to container of deferred events and will not be deleted as any other regular event.

How to repeat:
Pretty hard to reproduce

Suggested fix:
last_added= NULL
in Deferred_log_events::rewind
[30 Dec 2012 6:29] MySQL Verification Team
Setting verified based on code review.  I think a testcase would be environment, OS, and libc specific. Who knows what pointer would be returned next from malloc.
[30 Dec 2012 6:29] MySQL Verification Team
See https://bugs.launchpad.net/percona-server/+bug/1042946
[3 Jan 2013 8:12] MySQL Verification Team
bug #67384 is a duplicate
[31 Jan 2013 9:00] Jon Stephens
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release.

If necessary, you can access the source repository and build the latest available version, including the bug fix. More information about accessing the source trees is available at

[31 Jan 2013 9:01] Jon Stephens
Fixed in 5.5+, pushed to 5.5.31, 5.6.11, 5.7.1. Documented as follows:

        Using the --replicate-* options could in some cases lead to a
        memory leak on the slave.

[20 Apr 2013 13:48] Laurynas Biveinis
5.5$ bzr log -r 4175
revno: 4175
committer: Venkatesh Duggirala<venkatesh.duggirala@oracle.com>
branch nick: mysql-5.5
timestamp: Sat 2013-01-26 15:03:01 +0530
  Due to not resetting a member (last_added) of 
  Deferred events class inside a clean up function
  (Deferred_log_events::rewind), there is a memory
  leak on filtered slaves.
  Resetting last_added to NULL in rewind() function.

4674 in 5.6.
[25 Apr 2013 14:14] Jon Stephens
Also fixed in 5.1.70.
[26 Jun 2013 8:37] Laurynas Biveinis
5.1$ bzr log -r 3968
revno: 3968
committer: Venkatesh Duggirala<venkatesh.duggirala@oracle.com>
branch nick: mysql-5.1
timestamp: Fri 2013-03-15 08:56:20 +0530
  Back porting fix from mysql-5.5