From 6e3cf16ce4603aef72a63b27983148636db98d0a Mon Sep 17 00:00:00 2001 From: Serguey Zefirov Date: Mon, 23 Jun 2025 15:33:28 +0300 Subject: [PATCH] chore(MCOL-6018) Fix leaks in Columnstore information tables Fix introduces unique_ptr around DBRM instance in fill result functions. Now all paths lead to DBRM instance freeing. --- dbcon/mysql/is_columnstore_extents.cpp | 12 ++++++------ dbcon/mysql/is_columnstore_files.cpp | 13 ++++++------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/dbcon/mysql/is_columnstore_extents.cpp b/dbcon/mysql/is_columnstore_extents.cpp index b8f0cacf0..814e3c95e 100644 --- a/dbcon/mysql/is_columnstore_extents.cpp +++ b/dbcon/mysql/is_columnstore_extents.cpp @@ -202,7 +202,7 @@ static int is_columnstore_extents_fill(THD* thd, TABLE_LIST* tables, COND* cond) TABLE* table = tables->table; BRM::DBRM::refreshShmWithLock(); - BRM::DBRM* emp = new BRM::DBRM(); + std::unique_ptr emp(new BRM::DBRM()); if (!emp || !emp->isDBRMReady()) { @@ -224,7 +224,7 @@ static int is_columnstore_extents_fill(THD* thd, TABLE_LIST* tables, COND* cond) if (strcasecmp(item_field->field_name.str, "object_id") == 0) { cond_oid = fitem->arguments()[1]->val_int(); - return generate_result(cond_oid, emp, table, thd); + return generate_result(cond_oid, emp.get(), table, thd); } } else if (fitem->arguments()[1]->real_item()->type() == Item::FIELD_ITEM && @@ -236,7 +236,7 @@ static int is_columnstore_extents_fill(THD* thd, TABLE_LIST* tables, COND* cond) if (strcasecmp(item_field->field_name.str, "object_id") == 0) { cond_oid = fitem->arguments()[0]->val_int(); - return generate_result(cond_oid, emp, table, thd); + return generate_result(cond_oid, emp.get(), table, thd); } } } @@ -250,7 +250,7 @@ static int is_columnstore_extents_fill(THD* thd, TABLE_LIST* tables, COND* cond) for (unsigned int i = 1; i < fitem->argument_count(); i++) { cond_oid = fitem->arguments()[i]->val_int(); - int result = generate_result(cond_oid, emp, table, thd); + int result = generate_result(cond_oid, emp.get(), table, thd); if (result) return 1; @@ -266,7 +266,7 @@ static int is_columnstore_extents_fill(THD* thd, TABLE_LIST* tables, COND* cond) while (ss >> cond_oid) { - int ret = generate_result(cond_oid, emp, table, thd); + int ret = generate_result(cond_oid, emp.get(), table, thd); if (ret) return 1; @@ -282,7 +282,7 @@ static int is_columnstore_extents_fill(THD* thd, TABLE_LIST* tables, COND* cond) for (BRM::OID_t oid = 3000; oid <= MaxOID; oid++) { - int result = generate_result(oid, emp, table, thd); + int result = generate_result(oid, emp.get(), table, thd); if (result) return 1; diff --git a/dbcon/mysql/is_columnstore_files.cpp b/dbcon/mysql/is_columnstore_files.cpp index 11f64e1d2..19aea021b 100644 --- a/dbcon/mysql/is_columnstore_files.cpp +++ b/dbcon/mysql/is_columnstore_files.cpp @@ -216,7 +216,7 @@ static int generate_result(BRM::OID_t oid, BRM::DBRM* emp, TABLE* table, THD* th static int is_columnstore_files_fill(THD* thd, TABLE_LIST* tables, COND* cond) { BRM::DBRM::refreshShmWithLock(); - BRM::DBRM* emp = new BRM::DBRM(); + std::unique_ptr emp(new BRM::DBRM()); BRM::OID_t cond_oid = 0; TABLE* table = tables->table; @@ -240,7 +240,7 @@ static int is_columnstore_files_fill(THD* thd, TABLE_LIST* tables, COND* cond) if (strcasecmp(item_field->field_name.str, "object_id") == 0) { cond_oid = fitem->arguments()[1]->val_int(); - return generate_result(cond_oid, emp, table, thd); + return generate_result(cond_oid, emp.get(), table, thd); } } else if (fitem->arguments()[1]->real_item()->type() == Item::FIELD_ITEM && @@ -252,7 +252,7 @@ static int is_columnstore_files_fill(THD* thd, TABLE_LIST* tables, COND* cond) if (strcasecmp(item_field->field_name.str, "object_id") == 0) { cond_oid = fitem->arguments()[0]->val_int(); - return generate_result(cond_oid, emp, table, thd); + return generate_result(cond_oid, emp.get(), table, thd); } } } @@ -266,7 +266,7 @@ static int is_columnstore_files_fill(THD* thd, TABLE_LIST* tables, COND* cond) for (unsigned int i = 1; i < fitem->argument_count(); i++) { cond_oid = fitem->arguments()[i]->val_int(); - int result = generate_result(cond_oid, emp, table, thd); + int result = generate_result(cond_oid, emp.get(), table, thd); if (result) return 1; @@ -282,7 +282,7 @@ static int is_columnstore_files_fill(THD* thd, TABLE_LIST* tables, COND* cond) while (ss >> cond_oid) { - int ret = generate_result(cond_oid, emp, table, thd); + int ret = generate_result(cond_oid, emp.get(), table, thd); if (ret) return 1; @@ -300,14 +300,13 @@ static int is_columnstore_files_fill(THD* thd, TABLE_LIST* tables, COND* cond) { for (BRM::OID_t oid = 3000; oid <= MaxOID; oid++) { - int result = generate_result(oid, emp, table, thd); + int result = generate_result(oid, emp.get(), table, thd); if (result) return 1; } } - delete emp; return 0; }