Skip to content

Commit

Permalink
fix memory during MYSQL_BIN_LOG::open_existing_binlog
Browse files Browse the repository at this point in the history
Summary:
asandebug complain there are memory leaks during MYSQL_BIN_LOG open

Direct leak of 50 byte(s) in 1 object(s) allocated from:
    #0 0x67460ef in malloc
    #1 0x93f0777 in my_raw_malloc(unsigned long, int)
    #2 0x93f064a in my_malloc(unsigned int, unsigned long, int)
    #3 0x93f0eb0 in my_strdup(unsigned int, char const*, int)
    #4 0x8af01a6 in MYSQL_BIN_LOG::open(unsigned int, char const*, char const*, unsigned int)
    #5 0x8af8064 in MYSQL_BIN_LOG::open_binlog(char const*, char const*, unsigned long, bool, bool, bool, Format_description_log_event*, unsigned int, RaftRotateInfo*, bool)
    #6 0x8b00c00 in MYSQL_BIN_LOG::new_file_impl(bool, Format_description_log_event*, RaftRotateInfo*)
    #7 0x8d65e47 in rotate_relay_log(Master_info*, bool, bool, bool, RaftRotateInfo*)
    #8 0x8d661c0 in rotate_relay_log_for_raft(RaftRotateInfo*)
    #9 0x8c7696a in process_raft_queue
    #10 0xa0fa1fd in pfs_spawn_thread(void*)
    #11 0x7f8c9a12b20b in start_thread

release these memory before assign them

Reviewed By: Pushapgl

Differential Revision: D28819752

fbshipit-source-id: ed57cea875c
  • Loading branch information
luqun authored and inikep committed Nov 1, 2021
1 parent 2a6200e commit 84fff65
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 4 additions & 2 deletions sql/binlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6342,8 +6342,8 @@ bool MYSQL_BIN_LOG::open_existing_binlog(const char *log_name,
DBUG_RETURN(1);
}

if (!(this->name =
my_strdup(key_memory_MYSQL_LOG_name, log_name, MYF(MY_WME)))) {
my_free(name);
if (!(name = my_strdup(key_memory_MYSQL_LOG_name, log_name, MYF(MY_WME)))) {
// NO_LINT_DEBUG
sql_print_error("Could not allocate name %s (error %d)", log_name, errno);
DBUG_RETURN(1);
Expand All @@ -6353,6 +6353,8 @@ bool MYSQL_BIN_LOG::open_existing_binlog(const char *log_name,
Binlog_ofile::open_existing(m_key_file_log, existing_file, MYF(MY_WME));
if (!binlog_file) goto err;

// release current point before assign
delete m_binlog_file;
m_binlog_file = binlog_file.release();

file = mysql_file_open(m_key_file_log, existing_file, O_CREAT | O_WRONLY,
Expand Down
20 changes: 9 additions & 11 deletions sql/log_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4731,17 +4731,15 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli) {
}

int Query_log_event::do_apply_event_worker(Slave_worker *w) {
if (ends_group()) {
// Note: We're using event's future_event_relay_log_pos instead of
// rli->get_event_relay_log_pos() because rli is only updated in
// do_update_pos() which is called after applying the event and we might
// need to use this pos during application (e.g. during commit)
Slave_job_group *ptr_g = w->c_rli->gaq->get_job_group(mts_group_idx);
thd->set_trans_relay_log_pos(ptr_g->group_relay_log_name
? ptr_g->group_relay_log_name
: w->get_group_relay_log_name(),
future_event_relay_log_pos);
}
// Note: We're using event's future_event_relay_log_pos instead of
// rli->get_event_relay_log_pos() because rli is only updated in
// do_update_pos() which is called after applying the event and we might
// need to use this pos during application (e.g. during commit)
Slave_job_group *ptr_g = w->c_rli->gaq->get_job_group(mts_group_idx);
thd->set_trans_relay_log_pos(ptr_g->group_relay_log_name
? ptr_g->group_relay_log_name
: w->get_group_relay_log_name(),
future_event_relay_log_pos);
return do_apply_event(w, query, q_len);
}

Expand Down

0 comments on commit 84fff65

Please sign in to comment.