Skip to content

Commit

Permalink
Clean up the dynamically allocated memory
Browse files Browse the repository at this point in the history
  • Loading branch information
igniting committed Aug 7, 2014
1 parent 69e4017 commit 96754f3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 4 additions & 4 deletions sql/opt_costmodel.cc
Expand Up @@ -248,12 +248,12 @@ void Cost_factors::update_cost_factor(uint index, ulonglong ops, double value)
}
}

void Cost_factors::add_data(Cost_factors that)
void Cost_factors::add_data(Cost_factors *that)
{
has_unsaved_data= true;
global.update_global_factor(that.global);
for(engine_factor_map::iterator it= that.engine.begin();
it!= that.engine.end(); it++)
global.update_global_factor(that->global);
for(engine_factor_map::iterator it= that->engine.begin();
it!= that->engine.end(); it++)
{
engine_factor_map::iterator element= engine.find(it->first);
if(element != engine.end())
Expand Down
9 changes: 8 additions & 1 deletion sql/opt_costmodel.h
Expand Up @@ -158,12 +158,19 @@ class Cost_factors
void update_cost_factor(uint index, ulonglong total_ops, double value);

/* Add data from another Cost_factors object */
void add_data(Cost_factors that);
void add_data(Cost_factors *that);

/* Write data to optimizer_cost_factors table */
void write_to_table();

void cleanup();

~Cost_factors()
{
for(engine_factor_map::iterator it= engine.begin(); it != engine.end(); it++)
delete it->second;
engine.clear();
}
};

extern Cost_factors cost_factors;
Expand Down
3 changes: 1 addition & 2 deletions sql/sql_class.cc
Expand Up @@ -899,7 +899,6 @@ THD::THD()
wait_for_commit_ptr(0),
main_da(0, false, false),
m_stmt_da(&main_da),
thd_cost_factors(cost_factors),
equation_no(0),
unsaved_cost_factors(false),
utime_before_query(0)
Expand Down Expand Up @@ -1531,7 +1530,7 @@ void THD::cleanup(void)
if(unsaved_cost_factors)
{
mysql_mutex_lock(&cost_factors_lock);
cost_factors.add_data(thd_cost_factors);
cost_factors.add_data(&thd_cost_factors);
mysql_mutex_unlock(&cost_factors_lock);
}

Expand Down

0 comments on commit 96754f3

Please sign in to comment.