Skip to content

Commit a1f1e77

Browse files
Alexey KopytovAlexey Kopytov
Alexey Kopytov
authored and
Alexey Kopytov
committed
Bug #56709: Memory leaks at running the 5.1 test suite
Fixed a number of memory leaks discovered by valgrind.
1 parent 6baf9d5 commit a1f1e77

8 files changed

+61
-19
lines changed

dbug/dbug.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -455,13 +455,8 @@ static void DbugParse(CODE_STATE *cs, const char *control)
455455
rel= control[0] == '+' || control[0] == '-';
456456
if ((!rel || (!stack->out_file && !stack->next)))
457457
{
458-
/*
459-
We need to free what's already in init_settings, because unlike
460-
the thread related stack frames there's a chance that something
461-
is in these variables already.
462-
*/
463-
if (stack == &init_settings)
464-
FreeState(cs, stack, 0);
458+
/* Free memory associated with the state before resetting its members */
459+
FreeState(cs, stack, 0);
465460
stack->flags= 0;
466461
stack->delay= 0;
467462
stack->maxdepth= 0;
@@ -1447,8 +1442,8 @@ static void PushState(CODE_STATE *cs)
14471442
struct settings *new_malloc;
14481443

14491444
new_malloc= (struct settings *) DbugMalloc(sizeof(struct settings));
1445+
bzero(new_malloc, sizeof(struct settings));
14501446
new_malloc->next= cs->stack;
1451-
new_malloc->out_file= NULL;
14521447
cs->stack= new_malloc;
14531448
}
14541449

@@ -1957,7 +1952,7 @@ static FILE *OpenProfile(CODE_STATE *cs, const char *name)
19571952

19581953
static void DBUGCloseFile(CODE_STATE *cs, FILE *fp)
19591954
{
1960-
if (fp != stderr && fp != stdout && fclose(fp) == EOF)
1955+
if (fp != NULL && fp != stderr && fp != stdout && fclose(fp) == EOF)
19611956
{
19621957
pthread_mutex_lock(&THR_LOCK_dbug);
19631958
(void) fprintf(cs->stack->out_file, ERR_CLOSE, cs->process);

mysql-test/r/partition_error.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,4 +1008,14 @@ PARTITION p VALUES LESS THAN (1219089600),
10081008
PARTITION pmax VALUES LESS THAN MAXVALUE);
10091009
ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
10101010
DROP TABLE old;
1011+
#
1012+
# Bug #56709: Memory leaks at running the 5.1 test suite
1013+
#
1014+
CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY);
1015+
ALTER TABLE t1
1016+
PARTITION BY RANGE (EXTRACT(DAY FROM a)) (
1017+
PARTITION p VALUES LESS THAN (18),
1018+
PARTITION pmax VALUES LESS THAN MAXVALUE);
1019+
ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
1020+
DROP TABLE t1;
10111021
End of 5.1 tests

mysql-test/r/variables_debug.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,17 @@ SELECT @@global.debug;
2424
@@global.debug
2525

2626
SET GLOBAL debug=@old_debug;
27+
#
28+
# Bug #56709: Memory leaks at running the 5.1 test suite
29+
#
30+
SET @old_local_debug = @@debug;
31+
SET @@debug='d,foo';
32+
SELECT @@debug;
33+
@@debug
34+
d,foo
35+
SET @@debug='';
36+
SELECT @@debug;
37+
@@debug
38+
39+
SET @@debug = @old_local_debug;
2740
End of 5.1 tests

mysql-test/t/partition_error.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,4 +1252,18 @@ PARTITION pmax VALUES LESS THAN MAXVALUE);
12521252

12531253
DROP TABLE old;
12541254

1255+
--echo #
1256+
--echo # Bug #56709: Memory leaks at running the 5.1 test suite
1257+
--echo #
1258+
1259+
CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY);
1260+
1261+
--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
1262+
ALTER TABLE t1
1263+
PARTITION BY RANGE (EXTRACT(DAY FROM a)) (
1264+
PARTITION p VALUES LESS THAN (18),
1265+
PARTITION pmax VALUES LESS THAN MAXVALUE);
1266+
1267+
DROP TABLE t1;
1268+
12551269
--echo End of 5.1 tests

mysql-test/t/variables_debug.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,17 @@ SELECT @@global.debug;
2525

2626
SET GLOBAL debug=@old_debug;
2727

28+
--echo #
29+
--echo # Bug #56709: Memory leaks at running the 5.1 test suite
30+
--echo #
31+
32+
SET @old_local_debug = @@debug;
33+
34+
SET @@debug='d,foo';
35+
SELECT @@debug;
36+
SET @@debug='';
37+
SELECT @@debug;
38+
39+
SET @@debug = @old_local_debug;
40+
2841
--echo End of 5.1 tests

sql/item_timefunc.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,8 +2270,6 @@ void Item_extract::print(String *str, enum_query_type query_type)
22702270

22712271
void Item_extract::fix_length_and_dec()
22722272
{
2273-
value.alloc(32); // alloc buffer
2274-
22752273
maybe_null=1; // If wrong date
22762274
switch (int_type) {
22772275
case INTERVAL_YEAR: max_length=4; date_value=1; break;
@@ -2314,6 +2312,8 @@ longlong Item_extract::val_int()
23142312
}
23152313
else
23162314
{
2315+
char buf[40];
2316+
String value(buf, sizeof(buf), &my_charset_bin);;
23172317
String *res= args[0]->val_str(&value);
23182318
if (!res || str_to_time_with_warn(res->ptr(), res->length(), &ltime))
23192319
{

sql/item_timefunc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,6 @@ class Item_date_add_interval :public Item_date_func
702702

703703
class Item_extract :public Item_int_func
704704
{
705-
String value;
706705
bool date_value;
707706
public:
708707
const interval_type int_type; // keep it public

sql/sql_load.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,7 @@ READ_INFO::READ_INFO(File file_par, uint tot_length, CHARSET_INFO *cs,
11161116
MYF(MY_WME)))
11171117
{
11181118
my_free((uchar*) buffer,MYF(0)); /* purecov: inspected */
1119+
buffer= NULL;
11191120
error=1;
11201121
}
11211122
else
@@ -1142,13 +1143,10 @@ READ_INFO::READ_INFO(File file_par, uint tot_length, CHARSET_INFO *cs,
11421143

11431144
READ_INFO::~READ_INFO()
11441145
{
1145-
if (!error)
1146-
{
1147-
if (need_end_io_cache)
1148-
::end_io_cache(&cache);
1149-
my_free((uchar*) buffer,MYF(0));
1150-
error=1;
1151-
}
1146+
if (!error && need_end_io_cache)
1147+
::end_io_cache(&cache);
1148+
1149+
my_free(buffer, MYF(MY_ALLOW_ZERO_PTR));
11521150
}
11531151

11541152

0 commit comments

Comments
 (0)