diff options
author | unknown <knielsen@mysql.com> | 2006-05-15 18:07:18 +0200 |
---|---|---|
committer | unknown <knielsen@mysql.com> | 2006-05-15 18:07:18 +0200 |
commit | a046322b4e61aaef3db9efc9e85477792085c453 (patch) | |
tree | c90b581837f256bc8b3e0cb47cafcb159c99a19f /dbug | |
parent | 0a22763fa621e0d376e3e72febe2ad5df008a202 (diff) | |
download | mariadb-git-a046322b4e61aaef3db9efc9e85477792085c453.tar.gz |
Fix two Valgrind memory leak warnings.
client/mysqlbinlog.cc:
Now my_end() deallocates DBUG by default, but that fails in mysqlbinlog
because of global destructors that use DBUG.
dbug/dbug.c:
Add a facility to deallocate the debug stack, to avoid memory leak warnings
in Valgrind.
include/my_dbug.h:
Add a facility to deallocate the debug stack, to avoid memory leak warnings
in Valgrind.
include/my_sys.h:
Change my_end() to deallocate DBUG memory by default (can be disabled with
MY_DONT_FREE_DBUG option).
libmysql/libmysql.c:
Do not deallocate DBUG during cleanup.
mysys/my_init.c:
Change my_end() to deallocate DBUG memory by default (can be disabled with
MY_DONT_FREE_DBUG option).
sql/mysqld.cc:
Add missing my_thread_end() call, seems to occasionally trigger a memory
leak (not repeatable).
Diffstat (limited to 'dbug')
-rw-r--r-- | dbug/dbug.c | 84 |
1 files changed, 68 insertions, 16 deletions
diff --git a/dbug/dbug.c b/dbug/dbug.c index 91b7e7b6c4c..c991daf3617 100644 --- a/dbug/dbug.c +++ b/dbug/dbug.c @@ -271,6 +271,8 @@ static unsigned long Clock (void); static void CloseFile(FILE *fp); /* Push current debug state */ static void PushState(void); + /* Free memory associated with debug state. */ +static void FreeState (struct state *state); /* Test for tracing enabled */ static BOOLEAN DoTrace(CODE_STATE *state); /* Test to see if file is writable */ @@ -630,22 +632,7 @@ void _db_pop_ () stack = discard -> next_state; _db_fp_ = stack -> out_file; _db_pfp_ = stack -> prof_file; - if (discard -> keywords != NULL) { - FreeList (discard -> keywords); - } - if (discard -> functions != NULL) { - FreeList (discard -> functions); - } - if (discard -> processes != NULL) { - FreeList (discard -> processes); - } - if (discard -> p_functions != NULL) { - FreeList (discard -> p_functions); - } - CloseFile (discard -> out_file); - if (discard -> prof_file) - CloseFile (discard -> prof_file); - free ((char *) discard); + FreeState(discard); if (!(stack->flags & DEBUG_ON)) _db_on_=0; } @@ -1160,6 +1147,71 @@ static void PushState () stack=new_malloc; } +/* + * FUNCTION + * + * FreeState Free memory associated with a struct state. + * + * SYNOPSIS + * + * static void FreeState (state) + * struct state *state; + * + * DESCRIPTION + * + * Deallocates the memory allocated for various information in a + * state. + * + */ +static void FreeState ( +struct state *state) +{ + if (state -> keywords != NULL) { + FreeList (state -> keywords); + } + if (state -> functions != NULL) { + FreeList (state -> functions); + } + if (state -> processes != NULL) { + FreeList (state -> processes); + } + if (state -> p_functions != NULL) { + FreeList (state -> p_functions); + } + CloseFile (state -> out_file); + if (state -> prof_file) + CloseFile (state -> prof_file); + free ((char *) state); +} + + +/* + * FUNCTION + * + * _db_end_ End debugging, freeing state stack memory. + * + * SYNOPSIS + * + * static VOID _db_end_ () + * + * DESCRIPTION + * + * Ends debugging, de-allocating the memory allocated to the + * state stack. + * + * To be called at the very end of the program. + * + */ +void _db_end_ () +{ + reg1 struct state *discard; + while((discard= stack) != NULL) { + stack= discard -> next_state; + FreeState (discard); + } + _db_on_=0; +} + /* * FUNCTION |