aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-06-16 02:03:27 +1000
committerGravatar axel <axel@liljencrantz.se>2006-06-16 02:03:27 +1000
commitd2869d51405754594685514f205566bfef55f28b (patch)
treef0cef052d5ff977bfe7194dbf7e9669fc554b664
parent587e91d0c1173d91ba1256d3fb116d42d660e497 (diff)
Remove tiny and unlikely memory leak
darcs-hash:20060615160327-ac50b-01b0514c922104a7d36e3a9a0426bb3a671581b2.gz
-rw-r--r--history.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/history.c b/history.c
index 9bdddd4f..39db5c24 100644
--- a/history.c
+++ b/history.c
@@ -91,7 +91,7 @@ static hash_table_t history_table;
/**
Flag, set to 1 once the history file has been loaded
*/
-static int is_loaded;
+static int is_loaded=0;
/**
Load history from file
@@ -202,7 +202,7 @@ static void history_to_hash()
{
history_data *d;
- if( !history_last )
+ if( !mode_name )
return;
@@ -229,12 +229,22 @@ void history_set_mode( wchar_t *name )
if( mode_name )
{
+ /*
+ Move the current history to the hashtable
+ */
history_to_hash();
}
+
+ /*
+ See if the new history already exists
+ */
curr = (history_data *)hash_get( &history_table,
name );
if( curr )
{
+ /*
+ Yes. Restore it.
+ */
mode_name = (wchar_t *)hash_get_key( &history_table,
name );
history_current = history_last = curr->last;
@@ -244,6 +254,9 @@ void history_set_mode( wchar_t *name )
}
else
{
+ /*
+ Nope. Create a new history list.
+ */
history_count=0;
history_last = history_current = last_loaded=0;
mode_name = wcsdup( name );
@@ -370,7 +383,7 @@ static void history_destroy_mode( void *name, void *link )
past_end=1;
// fwprintf( stderr, L"Destroy history mode \'%ls\'\n", mode_name );
-
+
if( history_last )
{
history_save();
@@ -389,11 +402,12 @@ static void history_destroy_mode( void *name, void *link )
void history_destroy()
{
+
/**
Make sure current mode is in table
*/
history_to_hash();
-
+
/**
Save all modes in table
*/