Skip to content

Commit a7deb57

Browse files
committed
MDEV-39513 connect table_type=INI memory leak
The MRUProfile structure, of which CurProfile=MRUProfile[0] can contain a filename that is allocated. It is possible for the CurProfile to be null, while others are allocated, including those with a MRUProfile.filename already malloc. As such the full PROFILE_ReleaseFile needs to be called on all non-null MRUProfile entries to prevent a memory leak. Corrects MDEV-9997
1 parent f279551 commit a7deb57

4 files changed

Lines changed: 33 additions & 7 deletions

File tree

storage/connect/inihandl.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -621,17 +621,16 @@ void PROFILE_End(void)
621621
if (trace(3))
622622
htrc("PROFILE_End: CurProfile=%p N=%d\n", CurProfile, N_CACHED_PROFILES);
623623

624-
if (!CurProfile) // Sergey Vojtovich
625-
return;
626-
627624
/* Close all opened files and free the cache structure */
628625
for (i = 0; i < N_CACHED_PROFILES; i++) {
626+
CurProfile = MRUProfile[i];
627+
if (!CurProfile)
628+
continue;
629629
if (trace(3))
630-
htrc("MRU=%s i=%d\n", SVP(MRUProfile[i]->filename), i);
630+
htrc("MRU=%s i=%d\n", SVP(CurProfile->filename), i);
631631

632-
// CurProfile = MRUProfile[i]; Sergey Vojtovich
633-
// PROFILE_ReleaseFile(); see MDEV-9997
634-
free(MRUProfile[i]);
632+
PROFILE_ReleaseFile();
633+
memfree(CurProfile);
635634
} // endfor i
636635

637636
} // end of PROFILE_End
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#
2+
# MDEV-39513 connect table_type=INI memory leak
3+
#
4+
CREATE TABLE t (c INT) ENGINE=CONNECT table_type=INI file_name='MYSQLTEST_VARDIR/tmp/foobar';;
5+
UPDATE t SET c=0;
6+
DROP TABLE t;
7+
# End of 11.4 tests
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--secure_file_priv=$MYSQL_TMP_DIR
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
# This test requires that the ini subsystem of connect
3+
# hasn't been touched. Any call to PROFILE_Open will invalid
4+
# the that the MDEV causes.
5+
#
6+
--echo #
7+
--echo # MDEV-39513 connect table_type=INI memory leak
8+
--echo #
9+
10+
--source include/force_restart.inc
11+
12+
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
13+
--eval CREATE TABLE t (c INT) ENGINE=CONNECT table_type=INI file_name='$MYSQL_TMP_DIR/foobar';
14+
UPDATE t SET c=0;
15+
16+
--source include/force_restart.inc
17+
DROP TABLE t;
18+
19+
--echo # End of 11.4 tests

0 commit comments

Comments
 (0)