diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index 798ef511..9d4b0670 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -1722,9 +1722,21 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, client_flag|=mysql->options.client_flag; if (strncmp(end, "5.5.5-", 6) == 0) - mysql->server_version= my_strdup(end + 6, 0); + { + if (!(mysql->server_version= my_strdup(end + 6, 0))) + { + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); + goto error; + } + } else - mysql->server_version= my_strdup(end, MYF(0)); + { + if (!(mysql->server_version= my_strdup(end, MYF(0)))) + { + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); + goto error; + } + } end+= strlen(end) + 1; mysql->thread_id=uint4korr(end); @@ -1951,9 +1963,13 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, my_free(s_passwd,MYF(MY_ALLOW_ZERO_PTR)); my_free(s_db,MYF(MY_ALLOW_ZERO_PTR)); - mysql->user= my_strdup(user,MYF(MY_WME)); - mysql->passwd=my_strdup(passwd,MYF(MY_WME)); - mysql->db= db ? my_strdup(db,MYF(MY_WME)) : 0; + if (!(mysql->user= my_strdup(user,MYF(MY_WME))) || + !(mysql->passwd=my_strdup(passwd,MYF(MY_WME))) || + !(mysql->db= db ? my_strdup(db,MYF(MY_WME)) : 0)) + { + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); + rc= 1; + } for (;li_stmt;li_stmt= li_stmt->next) { diff --git a/libmariadb/my_stmt.c b/libmariadb/my_stmt.c index 417000ee..78535523 100644 --- a/libmariadb/my_stmt.c +++ b/libmariadb/my_stmt.c @@ -940,11 +940,11 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt) { DBUG_ENTER("mysql_stmt_close"); - if (stmt->mysql && stmt->mysql->net.vio) + if (stmt && stmt->mysql && stmt->mysql->net.vio) mysql_stmt_reset(stmt); net_stmt_close(stmt, 1); - my_free((char *)stmt->extension, MYF(MY_WME)); + my_free((char *)stmt->extension, MYF(MY_ALLOW_ZERO_PTR)); my_free((char *)stmt, MYF(MY_WME)); DBUG_RETURN(0); @@ -1237,6 +1237,7 @@ int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, unsigned lon SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto fail; } + memset(stmt->params, '\0', stmt->param_count * sizeof(MYSQL_BIND)); } /* allocated bind buffer for result */ if (stmt->field_count) diff --git a/unittest/libmariadb/basic-t.c b/unittest/libmariadb/basic-t.c index e11120f5..4565e493 100644 --- a/unittest/libmariadb/basic-t.c +++ b/unittest/libmariadb/basic-t.c @@ -499,7 +499,7 @@ static int test_reconnect_maxpackage(MYSQL *my) mysql_free_result(res); query= (char *)malloc(max_packet + 30); - memset(query, 0, max_packet); + memset(query, 0, max_packet + 30); strcpy(query, "SELECT '"); memset(query + 8, 'A', max_packet); diff --git a/unittest/libmariadb/fetch.c b/unittest/libmariadb/fetch.c index fe531fab..9050df86 100644 --- a/unittest/libmariadb/fetch.c +++ b/unittest/libmariadb/fetch.c @@ -533,7 +533,7 @@ static int test_fetch_null(MYSQL *mysql) MYSQL_STMT *stmt; int rc; int i; - long nData; + long nData= 0; MYSQL_BIND my_bind[11]; ulong length[11]; my_bool is_null[11]; @@ -713,9 +713,6 @@ static int test_fetch_date(MYSQL *mysql) FAIL_UNLESS(strcmp(ts, "2002-01-02 17:46:59") == 0, "ts != '2002-01-02 17:46:59'"); FAIL_UNLESS(ts_length == 19, "ts_length != 19"); - FAIL_UNLESS(year == 2010, "year != 2010"); - FAIL_UNLESS(y_length == 4, "y_length != 4"); - FAIL_UNLESS(strcmp(dt, "2010-07-10 00:00:00") == 0, "dt != 2010-07-10 00:00:00"); FAIL_UNLESS(dt_length == 19, "dt_length != 19"); diff --git a/unittest/libmariadb/ps.c b/unittest/libmariadb/ps.c index ca446fed..dcb6e089 100644 --- a/unittest/libmariadb/ps.c +++ b/unittest/libmariadb/ps.c @@ -381,6 +381,8 @@ static int test_prepare_syntax(MYSQL *mysql) rc= mysql_commit(mysql); check_mysql_rc(rc, mysql); + mysql_stmt_close(stmt); + return OK; } @@ -561,6 +563,8 @@ static int test_prepare_multi_statements(MYSQL *mysql) rc= mysql_stmt_prepare(stmt, query, strlen(query)); FAIL_IF(!rc, "Error expected"); + mysql_stmt_close(stmt); + return OK; } diff --git a/unittest/libmariadb/ps_new.c b/unittest/libmariadb/ps_new.c index 764f273a..dd509d63 100644 --- a/unittest/libmariadb/ps_new.c +++ b/unittest/libmariadb/ps_new.c @@ -334,6 +334,8 @@ int test_sp_reset2(MYSQL *mysql) long l[4]; char *stmtstr= "CALL P1()"; + memset(l, 0, sizeof(l)); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "CREATE TABLE t1 (a int)"); diff --git a/unittest/libmariadb/thread.c b/unittest/libmariadb/thread.c index f40652aa..1b8db900 100644 --- a/unittest/libmariadb/thread.c +++ b/unittest/libmariadb/thread.c @@ -114,13 +114,11 @@ DWORD WINAPI thread_conc27(void) #endif { MYSQL *mysql; - int rc, i; - char *hname[]= {"localhost", "127.0.0.1", NULL}; + int rc; mysql_thread_init(); mysql= mysql_init(NULL); - i= rand() % 3; - diag("Connecting to %s", hname[i]); - if(!mysql_real_connect(mysql, hname[i], username, password, schema, + MYSQL_RES *res; + if(!mysql_real_connect(mysql, hostname, username, password, schema, port, socketname, 0)) { diag("Error: %s", mysql_error(mysql)); @@ -132,7 +130,10 @@ DWORD WINAPI thread_conc27(void) rc= mysql_query(mysql, "UPDATE t_conc27 SET a=a+1"); check_mysql_rc(rc, mysql); pthread_mutex_unlock(&LOCK_test); - mysql_thread_end(); + rc= mysql_query(mysql, "SELECT SLEEP(5)"); + check_mysql_rc(rc, mysql); + if (res= mysql_store_result(mysql)) + mysql_free_result(res); mysql_close(mysql); end: mysql_thread_end();