Skip to content

Commit b044278

Browse files
author
Tor Didriksen
committed
Bug#14542543 FIX BUG #12694872 IN 5.5
Bug#14530242 CRASH / MEMORY CORRUPTION IN FILESORT_BUFFER::GET_RECORD_BUFFER WITH MYISAM This is a backport of Bug#12694872 - VALGRIND: 18,816 BYTES IN 196 BLOCKS ARE DEFINITELY LOST Bug#13340270: assertion table->sort.record_pointers == __null Bug#14536113 CRASH IN CLOSEFRM (TABLE.CC) OR UNPACK (FIELD.H) ON SUBQUERY WITH MYISAM TABLES Also: removed and re-added test files with file-ids from trunk.
1 parent 9f11f46 commit b044278

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

dbug/dbug.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_)
11791179
pthread_mutex_lock(&THR_LOCK_dbug);
11801180
DoPrefix(cs, _line_);
11811181
Indent(cs, cs->level);
1182-
(void) fprintf(cs->stack->out_file, "<%s\n", cs->func);
1182+
(void) fprintf(cs->stack->out_file, "<%s %u\n", cs->func, _line_);
11831183
DbugFlush(cs);
11841184
}
11851185
}

sql/filesort.cc

+3
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
138138
*/
139139
memcpy(&table_sort, &table->sort, sizeof(FILESORT_INFO));
140140
table->sort.io_cache= NULL;
141+
DBUG_ASSERT(table_sort.record_pointers == NULL);
141142

142143
outfile= table_sort.io_cache;
143144
my_b_clear(&tempfile);
@@ -366,6 +367,7 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
366367

367368
void filesort_free_buffers(TABLE *table, bool full)
368369
{
370+
DBUG_ENTER("filesort_free_buffers");
369371
my_free(table->sort.record_pointers);
370372
table->sort.record_pointers= NULL;
371373

@@ -383,6 +385,7 @@ void filesort_free_buffers(TABLE *table, bool full)
383385
my_free(table->sort.addon_field);
384386
table->sort.addon_buf= NULL;
385387
table->sort.addon_field= NULL;
388+
DBUG_VOID_RETURN;
386389
}
387390

388391
/** Make a array of string pointers. */

sql/opt_range.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#include "records.h" // init_read_record, end_read_record
7575
#include <m_ctype.h>
7676
#include "sql_select.h"
77+
#include "filesort.h" // filesort_free_buffers
7778

7879
#ifndef EXTRA_DEBUG
7980
#define test_rb_tree(A,B) {}
@@ -1246,7 +1247,8 @@ int QUICK_INDEX_MERGE_SELECT::init()
12461247
int QUICK_INDEX_MERGE_SELECT::reset()
12471248
{
12481249
DBUG_ENTER("QUICK_INDEX_MERGE_SELECT::reset");
1249-
DBUG_RETURN(read_keys_and_merge());
1250+
const int retval= read_keys_and_merge();
1251+
DBUG_RETURN(retval);
12501252
}
12511253

12521254
bool
@@ -8295,7 +8297,10 @@ int QUICK_INDEX_MERGE_SELECT::read_keys_and_merge()
82958297
thd->variables.sortbuff_size);
82968298
}
82978299
else
8300+
{
82988301
unique->reset();
8302+
filesort_free_buffers(head, false);
8303+
}
82998304

83008305
DBUG_ASSERT(file->ref_length == unique->get_size());
83018306
DBUG_ASSERT(thd->variables.sortbuff_size == unique->get_max_in_memory_size());

sql/sql_select.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -7173,14 +7173,14 @@ void JOIN::cleanup(bool full)
71737173
{
71747174
JOIN_TAB *tab,*end;
71757175
/*
7176-
Only a sorted table may be cached. This sorted table is always the
7177-
first non const table in join->all_tables
7176+
Free resources allocated by filesort() and Unique::get()
71787177
*/
71797178
if (tables > const_tables) // Test for not-const tables
7180-
{
7181-
free_io_cache(all_tables[const_tables]);
7182-
filesort_free_buffers(all_tables[const_tables],full);
7183-
}
7179+
for (uint ix= const_tables; ix < tables; ++ix)
7180+
{
7181+
free_io_cache(all_tables[ix]);
7182+
filesort_free_buffers(all_tables[ix], full);
7183+
}
71847184

71857185
if (full)
71867186
{

sql/uniques.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ int unique_write_to_ptrs(uchar* key, element_count count, Unique *unique)
5757

5858
Unique::Unique(qsort_cmp2 comp_func, void * comp_func_fixed_arg,
5959
uint size_arg, ulonglong max_in_memory_size_arg)
60-
:max_in_memory_size(max_in_memory_size_arg), size(size_arg), elements(0)
60+
:max_in_memory_size(max_in_memory_size_arg),
61+
record_pointers(NULL),
62+
size(size_arg),
63+
elements(0)
6164
{
6265
my_b_clear(&file);
6366
init_tree(&tree, (ulong) (max_in_memory_size / 16), 0, size, comp_func, 0,
@@ -583,6 +586,7 @@ bool Unique::get(TABLE *table)
583586
if (my_b_tell(&file) == 0)
584587
{
585588
/* Whole tree is in memory; Don't use disk if you don't need to */
589+
DBUG_ASSERT(table->sort.record_pointers == NULL);
586590
if ((record_pointers=table->sort.record_pointers= (uchar*)
587591
my_malloc(size * tree.elements_in_tree, MYF(0))))
588592
{
@@ -603,6 +607,7 @@ bool Unique::get(TABLE *table)
603607
bool error=1;
604608

605609
/* Open cached file if it isn't open */
610+
DBUG_ASSERT(table->sort.io_cache == NULL);
606611
outfile=table->sort.io_cache=(IO_CACHE*) my_malloc(sizeof(IO_CACHE),
607612
MYF(MY_ZEROFILL));
608613

0 commit comments

Comments
 (0)