Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix InactiveDestroy #175

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions dbdimp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2956,11 +2956,12 @@ mariadb_db_rollback(SV* dbh, imp_dbh_t* imp_dbh) {
return 1;
}

static void mariadb_dr_close_mysql(pTHX_ imp_drh_t *imp_drh, MYSQL *pmysql)
static void mariadb_dr_close_mysql(pTHX_ imp_drh_t *imp_drh, MYSQL *pmysql, bool actually_close)
{
if (pmysql)
{
mysql_close(pmysql);
if (actually_close)
mysql_close(pmysql);
imp_drh->instances--;
}
if (imp_drh->instances == 0)
Expand Down Expand Up @@ -3021,7 +3022,7 @@ static void mariadb_db_close_mysql(pTHX_ imp_drh_t *imp_drh, imp_dbh_t *imp_dbh)

if (imp_dbh->pmysql)
{
mariadb_dr_close_mysql(aTHX_ imp_drh, imp_dbh->pmysql);
mariadb_dr_close_mysql(aTHX_ imp_drh, imp_dbh->pmysql, DBIc_ACTIVE(imp_dbh));
imp_dbh->pmysql = NULL;
svp = hv_fetchs((HV*)DBIc_MY_H(imp_dbh), "ChildHandles", FALSE);
if (svp && *svp)
Expand Down Expand Up @@ -3059,6 +3060,8 @@ static void mariadb_db_close_mysql(pTHX_ imp_drh_t *imp_drh, imp_dbh_t *imp_dbh)
}
}
}

DBIc_ACTIVE_off(imp_dbh);
}

/*
Expand Down Expand Up @@ -3112,7 +3115,7 @@ int mariadb_dr_discon_all (SV *drh, imp_drh_t *imp_drh) {

while ((entry = imp_drh->taken_pmysqls))
{
mariadb_dr_close_mysql(aTHX_ imp_drh, (MYSQL *)entry->data);
mariadb_dr_close_mysql(aTHX_ imp_drh, (MYSQL *)entry->data, TRUE);
mariadb_list_remove(imp_drh->taken_pmysqls, entry);
}

Expand Down Expand Up @@ -5438,13 +5441,8 @@ void mariadb_st_destroy(SV *sth, imp_sth_t *imp_sth) {
int num_params;
int num_fields;

if (!PL_dirty)
{
/* During global destruction, DBI objects are destroyed in random order
* and therefore imp_dbh may be already freed. So do not access it. */
mariadb_st_finish(sth, imp_sth);
mariadb_st_free_result_sets(sth, imp_sth, TRUE);
}
if (imp_sth->result)
mysql_free_result(imp_sth->result);

DBIc_ACTIVE_off(imp_sth);

Expand Down