Skip to content

Commit 5dc1a14

Browse files
committed
BUG#34323788 - ASAN memory leaks reported by test_mysql_command_services_component.test
Fixed ASAN memory leaks reported by test_services.test_mysql_command_services_component.test This test case was introduced by wl#14293. Approved by: Bharathy Satish <bharathy.x.satish@oracle.com>
1 parent 6c50b99 commit 5dc1a14

File tree

5 files changed

+12
-4
lines changed

5 files changed

+12
-4
lines changed

components/test/test_mysql_command_services.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ static char *test_mysql_command_services_apis_udf(UDF_INIT *, UDF_ARGS *args,
295295
(result_set.length() < *length) ? result_set.length() : (*length - 1);
296296
result[*length] = '\0';
297297
}
298-
err:
299298
*error = 0;
299+
err:
300300
cmd_query_result_srv->free_result(mysql_res);
301301
cmd_factory_srv->close(mysql_h);
302302
return result;

sql-common/client.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,6 +1965,7 @@ void STDCALL mysql_free_result(MYSQL_RES *result) {
19651965
if (result->field_alloc) {
19661966
result->field_alloc->Clear();
19671967
my_free(result->field_alloc);
1968+
result->field_alloc = nullptr; // to avoid double free
19681969
}
19691970
my_free(result->row);
19701971
my_free(result);

sql/server_component/mysql_command_backend.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,10 @@ bool csi_advanced_command(MYSQL *mysql, enum enum_server_command command,
275275
}
276276

277277
mysql_handle.mysql = mysql;
278-
if (((class mysql_command_consumer_refs *)(command_consumer_srv))
279-
->factory_srv->start(&srv_ctx_h, (MYSQL_H *)&mysql_handle)) {
278+
if (mcs_extn->consumer_srv_data != nullptr)
279+
srv_ctx_h = reinterpret_cast<SRV_CTX_H>(mcs_extn->consumer_srv_data);
280+
else if (((class mysql_command_consumer_refs *)(command_consumer_srv))
281+
->factory_srv->start(&srv_ctx_h, (MYSQL_H *)&mysql_handle)) {
280282
sprintf(*err_msg, "Could not create %s service",
281283
"mysql_text_consumer_factory_v1");
282284
goto error;

sql/server_component/mysql_command_services_imp.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ DEFINE_BOOL_METHOD(mysql_command_services_imp::close, (MYSQL_H mysql_h)) {
230230
srv_session_detach(mcs_ext->session_svc);
231231
srv_session_close(mcs_ext->session_svc);
232232
}
233+
if (mysql->field_alloc) {
234+
mysql->field_alloc->Clear();
235+
my_free(mysql->field_alloc);
236+
mysql->field_alloc = nullptr;
237+
}
233238
mysql_close(mysql);
234239
my_free(mysql_h);
235240
}

sql/server_component/mysql_command_services_imp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct mysql_command_service_extn {
6262
if it was allocated. */
6363
MYSQL_DATA *data = nullptr;
6464
void *command_consumer_services = nullptr;
65-
SRV_CTX_H *consumer_srv_data;
65+
SRV_CTX_H *consumer_srv_data = nullptr;
6666
MYSQL_THD mcs_thd = nullptr;
6767
const char *mcs_protocol = nullptr;
6868
const char *mcs_user_name = nullptr;

0 commit comments

Comments
 (0)