summaryrefslogtreecommitdiff
path: root/dbug
diff options
context:
space:
mode:
authorknielsen@mysql.com <>2006-05-15 18:07:18 +0200
committerknielsen@mysql.com <>2006-05-15 18:07:18 +0200
commitfc16aff7423eff1eb52fcd2522b3454fa8748c70 (patch)
treec90b581837f256bc8b3e0cb47cafcb159c99a19f /dbug
parentf071779791d2bae55a03a6f2e158907a1f40ae5e (diff)
downloadmariadb-git-fc16aff7423eff1eb52fcd2522b3454fa8748c70.tar.gz
Fix two Valgrind memory leak warnings.
Diffstat (limited to 'dbug')
-rw-r--r--dbug/dbug.c84
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