Set --debug-check if one uses DBUG_PUSH in all clients

Fixed bug in query cache that made it impossible to run mysqld with --debug
Fixed memory leaks in mysqldump and mysqltest
Memory leaks associated with wrong usage of mysqltest is not fixed. To find these, run
mysql-test-run --debug mysqltest
This commit is contained in:
monty@mysql.com/nosik.monty.fi 2007-08-02 07:49:29 +03:00
parent 96f90711a7
commit 4f33d95fa3
10 changed files with 72 additions and 33 deletions

View File

@ -218,6 +218,7 @@ get_one_option(int optid, const struct my_option *opt,
case '#': case '#':
DBUG_PUSH(argument ? argument : default_dbug_option); DBUG_PUSH(argument ? argument : default_dbug_option);
add_option= FALSE; add_option= FALSE;
debug_check_flag= 1;
break; break;
case 'p': case 'p':

View File

@ -310,6 +310,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
break; break;
case '#': case '#':
DBUG_PUSH(argument ? argument : "d:t:o"); DBUG_PUSH(argument ? argument : "d:t:o");
debug_check_flag= 1;
break; break;
#include <sslopt-case.h> #include <sslopt-case.h>
case OPT_TABLES: case OPT_TABLES:

View File

@ -729,7 +729,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
break; break;
case '#': case '#':
DBUG_PUSH(argument ? argument : default_dbug_option); DBUG_PUSH(argument ? argument : default_dbug_option);
debug_info_flag= 1; debug_check_flag= 1;
break; break;
#include <sslopt-case.h> #include <sslopt-case.h>
case 'V': print_version(); exit(0); case 'V': print_version(); exit(0);
@ -2070,7 +2070,6 @@ static uint get_table_structure(char *table, char *db, char *table_type,
int len; int len;
MYSQL_RES *result; MYSQL_RES *result;
MYSQL_ROW row; MYSQL_ROW row;
DBUG_ENTER("get_table_structure"); DBUG_ENTER("get_table_structure");
DBUG_PRINT("enter", ("db: %s table: %s", db, table)); DBUG_PRINT("enter", ("db: %s table: %s", db, table));
@ -2472,6 +2471,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
fprintf(sql_file, " (%s)",row[7]); /* Sub key */ fprintf(sql_file, " (%s)",row[7]); /* Sub key */
check_io(sql_file); check_io(sql_file);
} }
mysql_free_result(result);
if (!opt_xml) if (!opt_xml)
{ {
if (keynr) if (keynr)
@ -2813,7 +2813,7 @@ static void dump_table(char *table, char *db)
/* /*
The "table" could be a view. If so, we don't do anything here. The "table" could be a view. If so, we don't do anything here.
*/ */
if (strcmp (table_type, "VIEW") == 0) if (strcmp(table_type, "VIEW") == 0)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
/* Check --no-data flag */ /* Check --no-data flag */
@ -2903,6 +2903,7 @@ static void dump_table(char *table, char *db)
if (mysql_real_query(mysql, query_string.str, query_string.length)) if (mysql_real_query(mysql, query_string.str, query_string.length))
{ {
DB_error(mysql, "when executing 'SELECT INTO OUTFILE'"); DB_error(mysql, "when executing 'SELECT INTO OUTFILE'");
dynstr_free(&query_string);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
} }
@ -3257,8 +3258,8 @@ static void dump_table(char *table, char *db)
check_io(md_result_file); check_io(md_result_file);
} }
mysql_free_result(res); mysql_free_result(res);
dynstr_free(&query_string);
} }
dynstr_free(&query_string);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
err: err:
@ -3379,6 +3380,7 @@ static int dump_tablespaces(char* ts_where)
char extra_format[]= "UNDO_BUFFER_SIZE="; char extra_format[]= "UNDO_BUFFER_SIZE=";
char *ubs; char *ubs;
char *endsemi; char *endsemi;
DBUG_ENTER("dump_tablespaces");
init_dynamic_string_checked(&sqlbuf, init_dynamic_string_checked(&sqlbuf,
"SELECT LOGFILE_GROUP_NAME," "SELECT LOGFILE_GROUP_NAME,"
@ -3410,6 +3412,7 @@ static int dump_tablespaces(char* ts_where)
if (mysql_query(mysql, sqlbuf.str) || if (mysql_query(mysql, sqlbuf.str) ||
!(tableres = mysql_store_result(mysql))) !(tableres = mysql_store_result(mysql)))
{ {
dynstr_free(&sqlbuf);
if (mysql_errno(mysql) == ER_BAD_TABLE_ERROR || if (mysql_errno(mysql) == ER_BAD_TABLE_ERROR ||
mysql_errno(mysql) == ER_BAD_DB_ERROR || mysql_errno(mysql) == ER_BAD_DB_ERROR ||
mysql_errno(mysql) == ER_UNKNOWN_TABLE) mysql_errno(mysql) == ER_UNKNOWN_TABLE)
@ -3418,12 +3421,12 @@ static int dump_tablespaces(char* ts_where)
"\n--\n-- Not dumping tablespaces as no INFORMATION_SCHEMA.FILES" "\n--\n-- Not dumping tablespaces as no INFORMATION_SCHEMA.FILES"
" table on this server\n--\n"); " table on this server\n--\n");
check_io(md_result_file); check_io(md_result_file);
return 0; DBUG_RETURN(0);
} }
my_printf_error(0, "Error: Couldn't dump tablespaces %s", my_printf_error(0, "Error: '%s' when trying to dump tablespaces",
MYF(0), mysql_error(mysql)); MYF(0), mysql_error(mysql));
return 1; DBUG_RETURN(1);
} }
buf[0]= 0; buf[0]= 0;
@ -3475,6 +3478,7 @@ static int dump_tablespaces(char* ts_where)
} }
} }
dynstr_free(&sqlbuf); dynstr_free(&sqlbuf);
mysql_free_result(tableres);
init_dynamic_string_checked(&sqlbuf, init_dynamic_string_checked(&sqlbuf,
"SELECT DISTINCT TABLESPACE_NAME," "SELECT DISTINCT TABLESPACE_NAME,"
" FILE_NAME," " FILE_NAME,"
@ -3492,7 +3496,10 @@ static int dump_tablespaces(char* ts_where)
dynstr_append_checked(&sqlbuf, " ORDER BY TABLESPACE_NAME, LOGFILE_GROUP_NAME"); dynstr_append_checked(&sqlbuf, " ORDER BY TABLESPACE_NAME, LOGFILE_GROUP_NAME");
if (mysql_query_with_error_report(mysql, &tableres, sqlbuf.str)) if (mysql_query_with_error_report(mysql, &tableres, sqlbuf.str))
return 1; {
dynstr_free(&sqlbuf);
DBUG_RETURN(1);
}
buf[0]= 0; buf[0]= 0;
while ((row= mysql_fetch_row(tableres))) while ((row= mysql_fetch_row(tableres)))
@ -3538,8 +3545,9 @@ static int dump_tablespaces(char* ts_where)
} }
} }
mysql_free_result(tableres);
dynstr_free(&sqlbuf); dynstr_free(&sqlbuf);
return 0; DBUG_RETURN(0);
} }
static int dump_all_databases() static int dump_all_databases()
@ -3626,8 +3634,11 @@ RETURN VALUES
0 Success. 0 Success.
1 Failure. 1 Failure.
*/ */
int init_dumping_tables(char *qdatabase) int init_dumping_tables(char *qdatabase)
{ {
DBUG_ENTER("init_dumping_tables");
if (!opt_create_db) if (!opt_create_db)
{ {
char qbuf[256]; char qbuf[256];
@ -3660,10 +3671,10 @@ int init_dumping_tables(char *qdatabase)
{ {
fprintf(md_result_file,"\n%s;\n",row[1]); fprintf(md_result_file,"\n%s;\n",row[1]);
} }
mysql_free_result(dbinfo);
} }
} }
DBUG_RETURN(0);
return 0;
} /* init_dumping_tables */ } /* init_dumping_tables */
@ -3931,8 +3942,13 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
} }
else else
{ {
maybe_die(EX_ILLEGAL_TABLE, "Couldn't find table: \"%s\"", *table_names); if (!ignore_errors)
/* We shall countinue here, if --force was given */ {
dynstr_free(&lock_tables_query);
free_root(&root, MYF(0));
}
maybe_die(EX_ILLEGAL_TABLE, "Couldn't find table: \"%s\"", *table_names);
/* We shall countinue here, if --force was given */
} }
} }
end= pos; end= pos;
@ -3941,14 +3957,25 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
{ {
if (mysql_real_query(mysql, lock_tables_query.str, if (mysql_real_query(mysql, lock_tables_query.str,
lock_tables_query.length-1)) lock_tables_query.length-1))
{
if (!ignore_errors)
{
dynstr_free(&lock_tables_query);
free_root(&root, MYF(0));
}
DB_error(mysql, "when doing LOCK TABLES"); DB_error(mysql, "when doing LOCK TABLES");
/* We shall countinue here, if --force was given */ /* We shall countinue here, if --force was given */
}
} }
dynstr_free(&lock_tables_query); dynstr_free(&lock_tables_query);
if (flush_logs) if (flush_logs)
{ {
if (mysql_refresh(mysql, REFRESH_LOG)) if (mysql_refresh(mysql, REFRESH_LOG))
{
if (!ignore_errors)
free_root(&root, MYF(0));
DB_error(mysql, "when doing refresh"); DB_error(mysql, "when doing refresh");
}
/* We shall countinue here, if --force was given */ /* We shall countinue here, if --force was given */
} }
if (opt_xml) if (opt_xml)
@ -4511,6 +4538,9 @@ static my_bool get_view_structure(char *table, char* db)
if (!(table_res= mysql_store_result(mysql)) || if (!(table_res= mysql_store_result(mysql)) ||
!(row= mysql_fetch_row(table_res))) !(row= mysql_fetch_row(table_res)))
{ {
if (table_res)
mysql_free_result(table_res);
dynstr_free(&ds_view);
DB_error(mysql, "when trying to save the result of SHOW CREATE TABLE in ds_view."); DB_error(mysql, "when trying to save the result of SHOW CREATE TABLE in ds_view.");
DBUG_RETURN(1); DBUG_RETURN(1);
} }

View File

@ -240,6 +240,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
break; break;
case '#': case '#':
DBUG_PUSH(argument ? argument : "d:t:o"); DBUG_PUSH(argument ? argument : "d:t:o");
debug_check_flag= 1;
break; break;
#include <sslopt-case.h> #include <sslopt-case.h>
case 'V': print_version(); exit(0); case 'V': print_version(); exit(0);

View File

@ -299,6 +299,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
break; break;
case '#': case '#':
DBUG_PUSH(argument ? argument : "d:t:o"); DBUG_PUSH(argument ? argument : "d:t:o");
debug_check_flag= 1;
break; break;
#include <sslopt-case.h> #include <sslopt-case.h>
case 'V': case 'V':

View File

@ -699,6 +699,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
break; break;
case '#': case '#':
DBUG_PUSH(argument ? argument : default_dbug_option); DBUG_PUSH(argument ? argument : default_dbug_option);
debug_check_flag= 1;
break; break;
#include <sslopt-case.h> #include <sslopt-case.h>
case 'V': case 'V':

View File

@ -809,10 +809,9 @@ void free_used_memory()
static void cleanup_and_exit(int exit_code) static void cleanup_and_exit(int exit_code)
{ {
free_used_memory(); free_used_memory();
my_end(my_end_arg | MY_CHECK_ERROR); my_end(my_end_arg);
if (!silent) if (!silent) {
{
switch (exit_code) { switch (exit_code) {
case 1: case 1:
printf("not ok\n"); printf("not ok\n");
@ -1085,8 +1084,7 @@ void check_result(DYNAMIC_STRING* ds)
DBUG_ENTER("check_result"); DBUG_ENTER("check_result");
DBUG_ASSERT(result_file_name); DBUG_ASSERT(result_file_name);
switch (dyn_string_cmp(ds, result_file_name)) switch (dyn_string_cmp(ds, result_file_name)) {
{
case RESULT_OK: case RESULT_OK:
break; /* ok */ break; /* ok */
case RESULT_LENGTH_MISMATCH: case RESULT_LENGTH_MISMATCH:
@ -1930,7 +1928,10 @@ void do_exec(struct st_command *command)
command->first_argument, ds_cmd.str)); command->first_argument, ds_cmd.str));
if (!(res_file= my_popen(&ds_cmd, "r")) && command->abort_on_error) if (!(res_file= my_popen(&ds_cmd, "r")) && command->abort_on_error)
{
dynstr_free(&ds_cmd);
die("popen(\"%s\", \"r\") failed", command->first_argument); die("popen(\"%s\", \"r\") failed", command->first_argument);
}
while (fgets(buf, sizeof(buf), res_file)) while (fgets(buf, sizeof(buf), res_file))
{ {
@ -1954,6 +1955,7 @@ void do_exec(struct st_command *command)
{ {
log_msg("exec of '%s failed, error: %d, status: %d, errno: %d", log_msg("exec of '%s failed, error: %d, status: %d, errno: %d",
ds_cmd.str, error, status, errno); ds_cmd.str, error, status, errno);
dynstr_free(&ds_cmd);
die("command \"%s\" failed", command->first_argument); die("command \"%s\" failed", command->first_argument);
} }
@ -1972,8 +1974,11 @@ void do_exec(struct st_command *command)
} }
} }
if (!ok) if (!ok)
{
dynstr_free(&ds_cmd);
die("command \"%s\" failed with wrong error: %d", die("command \"%s\" failed with wrong error: %d",
command->first_argument, status); command->first_argument, status);
}
} }
else if (command->expected_errors.err[0].type == ERR_ERRNO && else if (command->expected_errors.err[0].type == ERR_ERRNO &&
command->expected_errors.err[0].code.errnum != 0) command->expected_errors.err[0].code.errnum != 0)
@ -1981,6 +1986,7 @@ void do_exec(struct st_command *command)
/* Error code we wanted was != 0, i.e. not an expected success */ /* Error code we wanted was != 0, i.e. not an expected success */
log_msg("exec of '%s failed, error: %d, errno: %d", log_msg("exec of '%s failed, error: %d, errno: %d",
ds_cmd.str, error, errno); ds_cmd.str, error, errno);
dynstr_free(&ds_cmd);
die("command \"%s\" succeeded - should have failed with errno %d...", die("command \"%s\" succeeded - should have failed with errno %d...",
command->first_argument, command->expected_errors.err[0].code.errnum); command->first_argument, command->expected_errors.err[0].code.errnum);
} }
@ -4632,6 +4638,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case '#': case '#':
#ifndef DBUG_OFF #ifndef DBUG_OFF
DBUG_PUSH(argument ? argument : "d:t:S:i:O,/tmp/mysqltest.trace"); DBUG_PUSH(argument ? argument : "d:t:S:i:O,/tmp/mysqltest.trace");
debug_check_flag= 1;
#endif #endif
break; break;
case 'r': case 'r':
@ -5388,11 +5395,8 @@ end:
ds - dynamic string which is used for output buffer ds - dynamic string which is used for output buffer
NOTE NOTE
If there is an unexpected error this function will abort mysqltest If there is an unexpected error this function will abort mysqltest
immediately. immediately.
RETURN VALUE
error - function will not return
*/ */
void handle_error(struct st_command *command, void handle_error(struct st_command *command,

View File

@ -1184,7 +1184,7 @@ void _db_dump_(uint _line_, const char *keyword,
fprintf(cs->stack->out_file, "%s: ", cs->func); fprintf(cs->stack->out_file, "%s: ", cs->func);
} }
sprintf(dbuff,"%s: Memory: 0x%lx Bytes: (%ld)\n", sprintf(dbuff,"%s: Memory: 0x%lx Bytes: (%ld)\n",
keyword,(ulong) memory, length); keyword, (ulong) memory, (long) length);
(void) fputs(dbuff,cs->stack->out_file); (void) fputs(dbuff,cs->stack->out_file);
pos=0; pos=0;
@ -1449,6 +1449,7 @@ static void FreeState(CODE_STATE *cs, struct settings *state, int free_state)
FreeList(state->p_functions); FreeList(state->p_functions);
if (!is_shared(state, out_file)) if (!is_shared(state, out_file))
DBUGCloseFile(cs, state->out_file); DBUGCloseFile(cs, state->out_file);
(void) fflush(cs->stack->out_file);
if (state->prof_file) if (state->prof_file)
DBUGCloseFile(cs, state->prof_file); DBUGCloseFile(cs, state->prof_file);
if (free_state) if (free_state)
@ -1882,7 +1883,6 @@ static FILE *OpenProfile(CODE_STATE *cs, const char *name)
{ {
(void) fprintf(cs->stack->out_file, ERR_OPEN, cs->process, name); (void) fprintf(cs->stack->out_file, ERR_OPEN, cs->process, name);
perror(""); perror("");
dbug_flush(0);
(void) Delay(cs->stack->delay); (void) Delay(cs->stack->delay);
} }
else else
@ -1892,7 +1892,6 @@ static FILE *OpenProfile(CODE_STATE *cs, const char *name)
{ {
(void) fprintf(cs->stack->out_file, ERR_OPEN, cs->process, name); (void) fprintf(cs->stack->out_file, ERR_OPEN, cs->process, name);
perror(""); perror("");
dbug_flush(0);
} }
else else
{ {
@ -1931,7 +1930,7 @@ static void DBUGCloseFile(CODE_STATE *cs, FILE *fp)
pthread_mutex_lock(&THR_LOCK_dbug); pthread_mutex_lock(&THR_LOCK_dbug);
(void) fprintf(cs->stack->out_file, ERR_CLOSE, cs->process); (void) fprintf(cs->stack->out_file, ERR_CLOSE, cs->process);
perror(""); perror("");
dbug_flush(0); dbug_flush(cs);
} }
} }

View File

@ -134,14 +134,14 @@ void my_end(int infoflag)
We do not use DBUG_ENTER here, as after cleanup DBUG is no longer We do not use DBUG_ENTER here, as after cleanup DBUG is no longer
operational, so we cannot use DBUG_RETURN. operational, so we cannot use DBUG_RETURN.
*/ */
DBUG_PRINT("info",("Shutting down")); DBUG_PRINT("info",("Shutting down: infoflag: %d print_info: %d",
infoflag, print_info));
if (!info_file) if (!info_file)
{ {
info_file= stderr; info_file= stderr;
print_info= 0; print_info= 0;
} }
DBUG_PRINT("info",("Shutting down: print_info: %d", print_info));
if ((infoflag & MY_CHECK_ERROR) || print_info) if ((infoflag & MY_CHECK_ERROR) || print_info)
{ /* Test if some file is left open */ { /* Test if some file is left open */
@ -186,7 +186,7 @@ Voluntary context switches %ld, Involuntary context switches %ld\n",
fprintf(info_file,"\nRun time: %.1f\n",(double) clock()/CLOCKS_PER_SEC); fprintf(info_file,"\nRun time: %.1f\n",(double) clock()/CLOCKS_PER_SEC);
#endif #endif
#if defined(SAFEMALLOC) #if defined(SAFEMALLOC)
TERMINATE(stderr, 1); /* Give statistic on screen */ TERMINATE(stderr, (infoflag & MY_GIVE_INFO) != 0);
#elif defined(__WIN__) && defined(_MSC_VER) #elif defined(__WIN__) && defined(_MSC_VER)
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE ); _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR ); _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR );

View File

@ -862,6 +862,7 @@ Query_cache::Query_cache(ulong query_cache_limit_arg,
ulong Query_cache::resize(ulong query_cache_size_arg) ulong Query_cache::resize(ulong query_cache_size_arg)
{ {
ulong new_query_cache_size;
DBUG_ENTER("Query_cache::resize"); DBUG_ENTER("Query_cache::resize");
DBUG_PRINT("qcache", ("from %lu to %lu",query_cache_size, DBUG_PRINT("qcache", ("from %lu to %lu",query_cache_size,
query_cache_size_arg)); query_cache_size_arg));
@ -876,13 +877,13 @@ ulong Query_cache::resize(ulong query_cache_size_arg)
free_cache(); free_cache();
query_cache_size= query_cache_size_arg; query_cache_size= query_cache_size_arg;
ulong new_query_cache_size= init_cache(); new_query_cache_size= init_cache();
DBUG_EXECUTE("check_querycache",check_integrity(0););
STRUCT_LOCK(&structure_guard_mutex); STRUCT_LOCK(&structure_guard_mutex);
m_cache_status= Query_cache::NO_FLUSH_IN_PROGRESS; m_cache_status= Query_cache::NO_FLUSH_IN_PROGRESS;
pthread_cond_signal(&COND_cache_status_changed); pthread_cond_signal(&COND_cache_status_changed);
if (new_query_cache_size)
DBUG_EXECUTE("check_querycache",check_integrity(1););
STRUCT_UNLOCK(&structure_guard_mutex); STRUCT_UNLOCK(&structure_guard_mutex);
DBUG_RETURN(new_query_cache_size); DBUG_RETURN(new_query_cache_size);