From fbf6fd1598914801414b0b0a7f2a169b0506dc4c Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Sun, 21 Aug 2016 20:35:13 +0200 Subject: [PATCH] Valgrind fixes: - fixed 2 unitialized memory errors - fixed leak in client test --- libmariadb/mariadb_stmt.c | 4 ++-- unittest/libmariadb/bulk1.c | 2 ++ unittest/libmariadb/ps.c | 9 +++------ unittest/libmariadb/ps_bugs.c | 3 ++- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libmariadb/mariadb_stmt.c b/libmariadb/mariadb_stmt.c index ab3339ee..5ab301cc 100644 --- a/libmariadb/mariadb_stmt.c +++ b/libmariadb/mariadb_stmt.c @@ -501,7 +501,7 @@ int store_param(MYSQL_STMT *stmt, int column, unsigned char **p, unsigned long r MYSQL_TIME *t= (MYSQL_TIME *)ma_get_buffer_offset(stmt, stmt->params[column].buffer_type, stmt->params[column].buffer, row_nr); char t_buffer[MAX_DATETIME_STR_LEN]; - uint len; + uint len= 0; int2store(t_buffer + 1, t->year); t_buffer[3]= (char) t->month; @@ -512,7 +512,7 @@ int store_param(MYSQL_STMT *stmt, int column, unsigned char **p, unsigned long r if (t->second_part) { int4store(t_buffer + 8, t->second_part); - len= 12; + len= 11; } else if (t->hour || t->minute || t->second) len= 7; diff --git a/unittest/libmariadb/bulk1.c b/unittest/libmariadb/bulk1.c index 5500cb6f..0ab937d1 100644 --- a/unittest/libmariadb/bulk1.c +++ b/unittest/libmariadb/bulk1.c @@ -159,6 +159,8 @@ static int bulk2(MYSQL *mysql) rc= mysql_stmt_execute(stmt); check_stmt_rc(rc, stmt); + mysql_stmt_close(stmt); + return OK; } diff --git a/unittest/libmariadb/ps.c b/unittest/libmariadb/ps.c index 0be3033e..f66e2cd7 100644 --- a/unittest/libmariadb/ps.c +++ b/unittest/libmariadb/ps.c @@ -184,7 +184,6 @@ static int test_bind_date_conv(MYSQL *mysql, uint row_count) { MYSQL_STMT *stmt= 0; uint rc, i, count= row_count; - ulong length[4]= {0,0,0,0}; MYSQL_BIND my_bind[4]; my_bool is_null[4]= {0,0,0,0}; MYSQL_TIME tm[4]; @@ -203,7 +202,6 @@ static int test_bind_date_conv(MYSQL *mysql, uint row_count) its members. */ memset(my_bind, '\0', sizeof(my_bind)); - memset(tm, 0, sizeof(tm)); my_bind[0].buffer_type= MYSQL_TYPE_TIMESTAMP; my_bind[1].buffer_type= MYSQL_TYPE_TIME; @@ -214,9 +212,7 @@ static int test_bind_date_conv(MYSQL *mysql, uint row_count) { my_bind[i].buffer= (void *) &tm[i]; my_bind[i].is_null= &is_null[i]; - my_bind[i].length= &length[i]; - my_bind[i].buffer_length= 30; - length[i]= 20; + my_bind[i].buffer_length= sizeof(MYSQL_TIME); } second_part= 0; @@ -236,6 +232,7 @@ static int test_bind_date_conv(MYSQL *mysql, uint row_count) { for (i= 0; i < (int) array_elements(my_bind); i++) { + memset(&tm[i], 0, sizeof(MYSQL_TIME)); tm[i].neg= 0; tm[i].second_part= second_part+count; if (my_bind[i].buffer_type != MYSQL_TYPE_TIME) @@ -3414,7 +3411,6 @@ static int test_double_compare(MYSQL *mysql) my_bind[1].buffer= (void *)&real_data; my_bind[1].buffer_length= sizeof(real_data); my_bind[1].length= &length[1]; - length[1]= 10; /* double */ my_bind[2].buffer_type= MYSQL_TYPE_DOUBLE; @@ -3422,6 +3418,7 @@ static int test_double_compare(MYSQL *mysql) tiny_data= 1; strcpy(real_data, "10.2"); + length[1]= strlen(real_data); double_data= 34.5; rc= mysql_stmt_bind_param(stmt, my_bind); check_stmt_rc(rc, stmt); diff --git a/unittest/libmariadb/ps_bugs.c b/unittest/libmariadb/ps_bugs.c index da10c396..539f0a65 100644 --- a/unittest/libmariadb/ps_bugs.c +++ b/unittest/libmariadb/ps_bugs.c @@ -3028,7 +3028,7 @@ static int test_bug8330(MYSQL *mysql) int i, rc; const char *query= "select a,b from t1 where a=?"; MYSQL_BIND my_bind[2]; - long lval[2]; + long lval[2]= {1,2}; stmt_text= "drop table if exists t1"; /* in case some previos test failed */ @@ -3354,6 +3354,7 @@ static int test_decimal_bug(MYSQL *mysql) */ memset(my_bind, '\0', sizeof(my_bind)); + memset(data, 0, sizeof(data)); my_bind[0].buffer_type= MYSQL_TYPE_NEWDECIMAL; my_bind[0].buffer= (void *)data; my_bind[0].buffer_length= 25;