Skip to content

Commit 33a9d9f

Browse files
author
Sergey Vojtovich
committed
BUG#12402794 - 60976: CRASH, VALGRIND WARNING AND MEMORY
LEAK WITH PARTITIONED ARCHIVE TABLES CHECK TABLE against archive table, when file descriptors are exhausted, caused server crash. Archive didn't handle errors when opening data file for CHECK TABLE.
1 parent 4731736 commit 33a9d9f

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

mysql-test/r/archive_debug.result

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# BUG#12402794 - 60976: CRASH, VALGRIND WARNING AND MEMORY LEAK
3+
# WITH PARTITIONED ARCHIVE TABLES
4+
#
5+
CREATE TABLE t1(a INT) ENGINE=ARCHIVE;
6+
INSERT INTO t1 VALUES(1);
7+
SET SESSION debug='d,simulate_archive_open_failure';
8+
CHECK TABLE t1;
9+
Table Op Msg_type Msg_text
10+
test.t1 check error Corrupt
11+
SET SESSION debug=DEFAULT;
12+
DROP TABLE t1;

mysql-test/t/archive_debug.test

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--source include/have_archive.inc
2+
--source include/have_debug.inc
3+
4+
--echo #
5+
--echo # BUG#12402794 - 60976: CRASH, VALGRIND WARNING AND MEMORY LEAK
6+
--echo # WITH PARTITIONED ARCHIVE TABLES
7+
--echo #
8+
CREATE TABLE t1(a INT) ENGINE=ARCHIVE;
9+
INSERT INTO t1 VALUES(1);
10+
SET SESSION debug='d,simulate_archive_open_failure';
11+
CHECK TABLE t1;
12+
SET SESSION debug=DEFAULT;
13+
DROP TABLE t1;

storage/archive/azio.c

+9
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ int az_open (azio_stream *s, const char *path, int Flags, File fd)
114114

115115
errno = 0;
116116
s->file = fd < 0 ? my_open(path, Flags, MYF(0)) : fd;
117+
DBUG_EXECUTE_IF("simulate_archive_open_failure",
118+
{
119+
if (s->file >= 0)
120+
{
121+
my_close(s->file, MYF(0));
122+
s->file= -1;
123+
my_errno= EMFILE;
124+
}
125+
});
117126

118127
if (s->file < 0 )
119128
{

storage/archive/ha_archive.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1586,11 +1586,12 @@ int ha_archive::check(THD* thd, HA_CHECK_OPT* check_opt)
15861586
azflush(&(share->archive_write), Z_SYNC_FLUSH);
15871587
pthread_mutex_unlock(&share->mutex);
15881588

1589+
if (init_archive_reader())
1590+
DBUG_RETURN(HA_ADMIN_CORRUPT);
15891591
/*
15901592
Now we will rewind the archive file so that we are positioned at the
15911593
start of the file.
15921594
*/
1593-
init_archive_reader();
15941595
read_data_header(&archive);
15951596
while (!(rc= get_row(&archive, table->record[0])))
15961597
count--;

0 commit comments

Comments
 (0)