diff options
author | 2006-10-21 20:30:35 +1000 | |
---|---|---|
committer | 2006-10-21 20:30:35 +1000 | |
commit | ed36f30eae9efbc0137380ea3c368b9a5d0cf409 (patch) | |
tree | 50aefa0a820865250d30e535b9edad7ed776b93d /history.c | |
parent | 7b8ebdadd6d10bded2a02da44e95b3bcba6c086a (diff) |
Fix crash bug in new history code - fish would segfauls in non-interactive mode on exit
darcs-hash:20061021103035-ac50b-a2a8d96416ff217cc5640f8f27db8dbac2c39b82.gz
Diffstat (limited to 'history.c')
-rw-r--r-- | history.c | 28 |
1 files changed, 19 insertions, 9 deletions
@@ -366,7 +366,7 @@ static void item_write( FILE *f, history_mode_t *m, void *v ) /** Release all memory used by the specified history mode. */ -static void history_destroy_mode( wchar_t *name, history_mode_t *m ) +static void history_destroy_mode( history_mode_t *m ) { halloc_free( m->item_context ); @@ -375,11 +375,16 @@ static void history_destroy_mode( wchar_t *name, history_mode_t *m ) munmap( m->mmap_start, m->mmap_length); } +} + +static void history_destroy_mode_wrapper( void *n, history_mode_t *m ) +{ halloc_free( m ); } /** - Create a new empty mode with the specified name + Create a new empty mode with the specified name. + The mode is a halloc context, and the entire mode can be destroyed using halloc_free(). */ static history_mode_t *history_create_mode( const wchar_t *name ) { @@ -395,6 +400,8 @@ static history_mode_t *history_create_mode( const wchar_t *name ) new_mode->save_timestamp=time(0); new_mode->item_context = halloc( 0,0 ); + halloc_register_function( new_mode, (void (*)(void *))&history_destroy_mode, new_mode ); + return new_mode; } @@ -649,7 +656,7 @@ static void history_save_mode( void *n, history_mode_t *m ) free( tmp_name ); } - history_destroy_mode( 0, on_disk); + halloc_free( on_disk); /* if( m->mmap_start && (m->mmap_start != MAP_FAILED ) ) munmap( m->mmap_start, m->mmap_length ); @@ -862,17 +869,20 @@ void history_set_mode( const wchar_t *name ) } void history_init() -{ +{ } void history_destroy() { - hash_foreach( mode_table, (void (*)(void *, void *))&history_save_mode ); - hash_foreach( mode_table, (void (*)(void *, void *))&history_destroy_mode ); - hash_destroy( mode_table ); - free( mode_table ); - mode_table=0; + if( mode_table ) + { + hash_foreach( mode_table, (void (*)(void *, void *))&history_save_mode ); + hash_foreach( mode_table, (void (*)(void *, void *))&history_destroy_mode_wrapper ); + hash_destroy( mode_table ); + free( mode_table ); + mode_table=0; + } } |