Skip to content

Commit 65f831d

Browse files
committed
Fixed bugs found by valgrind
- Some of the bug fixes are backports from 10.5! - The fix in innobase/fil/fil0fil.cc is just a backport to get less error messages in mysqld.1.err when running with valgrind. - Renamed HAVE_valgrind_or_MSAN to HAVE_valgrind
1 parent 29f9e67 commit 65f831d

32 files changed

+171
-126
lines changed

client/mysqltest.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10179,7 +10179,7 @@ void append_replace_regex(char* expr, char *expr_end, struct st_replace_regex* r
1017910179
/* Allow variable for the *entire* list of replacements */
1018010180
if (*p == '$')
1018110181
{
10182-
const char *v_end;
10182+
const char *v_end= 0;
1018310183
VAR *val= var_get(p, &v_end, 0, 1);
1018410184

1018510185
if (val)
@@ -10820,7 +10820,7 @@ REPLACE *init_replace(char * *from, char * *to,uint count,
1082010820
for (i=1 ; i <= found_sets ; i++)
1082110821
{
1082210822
pos=from[found_set[i-1].table_offset];
10823-
rep_str[i].found= !memcmp(pos, "\\^", 3) ? 2 : 1;
10823+
rep_str[i].found= !strncmp(pos, "\\^", 3) ? 2 : 1;
1082410824
rep_str[i].replace_string=to_array[found_set[i-1].table_offset];
1082510825
rep_str[i].to_offset=found_set[i-1].found_offset-start_at_word(pos);
1082610826
rep_str[i].from_offset=found_set[i-1].found_offset-replace_len(pos)+
@@ -11132,13 +11132,16 @@ void replace_dynstr_append_mem(DYNAMIC_STRING *ds, const char *val, size_t len)
1113211132
{
1113311133
/* Convert to lower case, and do this first */
1113411134
char *c= lower;
11135-
for (const char *v= val; *v; v++)
11135+
for (const char *v= val, *end_v= v + len; v < end_v; v++)
1113611136
*c++= my_tolower(charset_info, *v);
1113711137
*c= '\0';
1113811138
/* Copy from this buffer instead */
1113911139
}
1114011140
else
11141-
memcpy(lower, val, len+1);
11141+
{
11142+
memcpy(lower, val, len);
11143+
lower[len]= 0;
11144+
}
1114211145
fix_win_paths(lower, len);
1114311146
val= lower;
1114411147
}

include/my_sys.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ static inline int my_b_read(IO_CACHE *info, uchar *Buffer, size_t Count)
535535

536536
static inline int my_b_write(IO_CACHE *info, const uchar *Buffer, size_t Count)
537537
{
538+
MEM_CHECK_DEFINED(Buffer, Count);
538539
if (info->write_pos + Count <= info->write_end)
539540
{
540541
memcpy(info->write_pos, Buffer, Count);
@@ -556,6 +557,7 @@ static inline int my_b_get(IO_CACHE *info)
556557

557558
static inline my_bool my_b_write_byte(IO_CACHE *info, uchar chr)
558559
{
560+
MEM_CHECK_DEFINED(&chr, 1);
559561
if (info->write_pos >= info->write_end)
560562
if (my_b_flush_io_cache(info, 1))
561563
return 1;

include/my_valgrind.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@
2424
# define __SANITIZE_ADDRESS__ 1
2525
#endif
2626

27-
#ifdef HAVE_valgrind
28-
#define IF_VALGRIND(A,B) A
29-
#else
30-
#define IF_VALGRIND(A,B) B
31-
#endif
32-
33-
#if defined(HAVE_VALGRIND_MEMCHECK_H) && defined(HAVE_valgrind)
27+
#if __has_feature(memory_sanitizer)
28+
# include <sanitizer/msan_interface.h>
29+
# define HAVE_valgrind
30+
# define MEM_UNDEFINED(a,len) __msan_allocated_memory(a,len)
31+
# define MEM_MAKE_DEFINED(a,len) __msan_unpoison(a,len)
32+
# define MEM_NOACCESS(a,len) ((void) 0)
33+
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
34+
# define MEM_CHECK_DEFINED(a,len) __msan_check_mem_is_initialized(a,len)
35+
# define MEM_GET_VBITS(a,b,len) __msan_copy_shadow(b,a,len)
36+
# define MEM_SET_VBITS(a,b,len) __msan_copy_shadow(a,b,len)
37+
# define REDZONE_SIZE 8
38+
#elif defined(HAVE_VALGRIND_MEMCHECK_H) && defined(HAVE_valgrind)
3439
# include <valgrind/memcheck.h>
35-
# define HAVE_valgrind_or_MSAN
3640
# define MEM_UNDEFINED(a,len) VALGRIND_MAKE_MEM_UNDEFINED(a,len)
3741
# define MEM_MAKE_DEFINED(a,len) VALGRIND_MAKE_MEM_DEFINED(a,len)
3842
# define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len)
@@ -53,17 +57,6 @@
5357
# define MEM_GET_VBITS(a,b,len) ((void) 0)
5458
# define MEM_SET_VBITS(a,b,len) ((void) 0)
5559
# define REDZONE_SIZE 8
56-
#elif __has_feature(memory_sanitizer)
57-
# include <sanitizer/msan_interface.h>
58-
# define HAVE_valgrind_or_MSAN
59-
# define MEM_UNDEFINED(a,len) __msan_allocated_memory(a,len)
60-
# define MEM_MAKE_DEFINED(a,len) __msan_unpoison(a,len)
61-
# define MEM_NOACCESS(a,len) ((void) 0)
62-
# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0)
63-
# define MEM_CHECK_DEFINED(a,len) __msan_check_mem_is_initialized(a,len)
64-
# define MEM_GET_VBITS(a,b,len) __msan_copy_shadow(b,a,len)
65-
# define MEM_SET_VBITS(a,b,len) __msan_copy_shadow(a,b,len)
66-
# define REDZONE_SIZE 8
6760
#else
6861
# define MEM_UNDEFINED(a,len) ((void) (a), (void) (len))
6962
# define MEM_MAKE_DEFINED(a,len) ((void) 0)
@@ -73,7 +66,14 @@
7366
# define MEM_GET_VBITS(a,b,len) ((void) 0)
7467
# define MEM_SET_VBITS(a,b,len) ((void) 0)
7568
# define REDZONE_SIZE 0
76-
#endif /* HAVE_VALGRIND_MEMCHECK_H */
69+
#endif /* __has_feature(memory_sanitizer) */
70+
71+
#ifdef HAVE_valgrind
72+
#define IF_VALGRIND(A,B) A
73+
#else
74+
#define IF_VALGRIND(A,B) B
75+
#endif
76+
7777

7878
#ifdef TRASH_FREED_MEMORY
7979
/*

mysql-test/main/sp-big.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ end//
8080
insert t1 select seq, seq, 1, 1, seq, seq, seq from seq_1_to_2000;
8181
set @before=unix_timestamp();
8282
call select_test();
83-
select unix_timestamp() - @before < 60;
84-
unix_timestamp() - @before < 60
83+
select unix_timestamp() - @before < @time;
84+
unix_timestamp() - @before < @time
8585
1
8686
drop procedure select_test;
8787
drop table t1;

mysql-test/main/sp-big.test

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,17 @@ delimiter ;//
112112
insert t1 select seq, seq, 1, 1, seq, seq, seq from seq_1_to_2000;
113113
set @before=unix_timestamp();
114114
call select_test();
115-
select unix_timestamp() - @before < 60;
115+
116+
--let $time=60
117+
if ($VALGRIND_TEST)
118+
{
119+
--let $time=600
120+
}
121+
122+
--disable_query_log
123+
--eval set @time=$time;
124+
--enable_query_log
125+
126+
select unix_timestamp() - @before < @time;
116127
drop procedure select_test;
117128
drop table t1;

sql/field.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7686,7 +7686,7 @@ my_decimal *Field_varstring::val_decimal(my_decimal *decimal_value)
76867686
}
76877687

76887688

7689-
#ifdef HAVE_valgrind_or_MSAN
7689+
#ifdef HAVE_valgrind
76907690
void Field_varstring::mark_unused_memory_as_defined()
76917691
{
76927692
uint used_length= get_length();

sql/field.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ class Field: public Value_source
826826
return store(ls.str, (uint) ls.length, cs);
827827
}
828828

829-
#ifdef HAVE_valgrind_or_MSAN
829+
#ifdef HAVE_valgrind
830830
/**
831831
Mark unused memory in the field as defined. Mainly used to ensure
832832
that if we write full field to disk (for example in
@@ -3466,7 +3466,7 @@ class Field_varstring :public Field_longstr {
34663466
bool memcpy_field_possible(const Field *from) const;
34673467
int store(const char *to,size_t length,CHARSET_INFO *charset);
34683468
using Field_str::store;
3469-
#ifdef HAVE_valgrind_or_MSAN
3469+
#ifdef HAVE_valgrind
34703470
void mark_unused_memory_as_defined();
34713471
#endif
34723472
double val_real(void);
@@ -4395,7 +4395,8 @@ class Column_definition: public Sql_alloc,
43954395
:Type_handler_hybrid_field_type(&type_handler_null),
43964396
compression_method_ptr(0),
43974397
comment(null_clex_str),
4398-
on_update(NULL), length(0), invisible(VISIBLE), decimals(0),
4398+
on_update(NULL), length(0), invisible(VISIBLE), char_length(0),
4399+
decimals(0),
43994400
flags(0), pack_length(0), key_length(0), unireg_check(Field::NONE),
44004401
interval(0), charset(&my_charset_bin),
44014402
srid(0), geom_type(Field::GEOM_GEOMETRY),

sql/ha_partition.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2548,7 +2548,7 @@ register_query_cache_dependant_tables(THD *thd,
25482548
sub_elem= subpart_it++;
25492549
part= i * num_subparts + j;
25502550
/* we store the end \0 as part of the key */
2551-
end= strmov(engine_pos, sub_elem->partition_name);
2551+
end= strmov(engine_pos, sub_elem->partition_name) + 1;
25522552
length= (uint)(end - engine_key);
25532553
/* Copy the suffix also to query cache key */
25542554
memcpy(query_cache_key_end, engine_key_end, (end - engine_key_end));

sql/item_cmpfunc.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,8 @@ longlong Item_func_truth::val_int()
11761176

11771177
bool Item_in_optimizer::is_top_level_item()
11781178
{
1179+
if (invisible_mode())
1180+
return FALSE;
11791181
return ((Item_in_subselect *)args[1])->is_top_level_item();
11801182
}
11811183

sql/item_subselect.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ bool Item_subselect::exec()
717717

718718
push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
719719
ER_UNKNOWN_ERROR, "DBUG: Item_subselect::exec %.*s",
720-
print.length(),print.c_ptr());
720+
print.length(),print.ptr());
721721
);
722722
/*
723723
Do not execute subselect in case of a fatal error

0 commit comments

Comments
 (0)