diff --git a/src/friso.c b/src/friso.c index 993619f..e54eb12 100644 --- a/src/friso.c +++ b/src/friso.c @@ -1312,7 +1312,7 @@ FRISO_API friso_hits_t friso_next( string_buffer_t sb = NULL; lex_entry_t lex = NULL, tmp = NULL, sword = NULL; - /* {{{ task buffer check */ + /* {{{ task word pool check */ if ( ! link_list_empty( task->pool ) ) { /* * load word from the word poll if it is not empty. diff --git a/src/friso_API.h b/src/friso_API.h index f6e32c2..9acc249 100644 --- a/src/friso_API.h +++ b/src/friso_API.h @@ -337,7 +337,7 @@ FRISO_API void free_hash_table( friso_hash_t, fhash_callback_fn_t ); * ---------------------------------------- * the function associates the specified key with the given value. */ -FRISO_API void hash_put_mapping( friso_hash_t, fstring, void * ); +FRISO_API void *hash_put_mapping( friso_hash_t, fstring, void * ); /* * Function: is_mapping_exists diff --git a/src/friso_hash.c b/src/friso_hash.c index 46d9434..400487f 100644 --- a/src/friso_hash.c +++ b/src/friso_hash.c @@ -188,13 +188,14 @@ FRISO_API void free_hash_table( //put a new mapping insite. //the value cannot be NULL. -FRISO_API void hash_put_mapping( +FRISO_API void *hash_put_mapping( friso_hash_t _hash, fstring key, void * value ) { uint_t bucket = ( key == NULL ) ? 0 : hash( key, _hash->length ); hash_entry_t e = *( _hash->table + bucket ); + void *oval = NULL; //check the given key is already exists or not. for ( ; e != NULL; e = e->_next ) @@ -203,8 +204,9 @@ FRISO_API void hash_put_mapping( || ( key != NULL && e->_key != NULL && strcmp( key, e->_key ) == 0 ) ) { + oval = e->_val; //bak the old value e->_val = value; - return; + return oval; } } @@ -216,6 +218,7 @@ FRISO_API void hash_put_mapping( if ( _hash->size >= _hash->threshold ) rebuild_hash( _hash ); + return oval; } //check the existence of the mapping associated with the given key. diff --git a/src/friso_lexicon.c b/src/friso_lexicon.c index 15e95a6..7341ea2 100644 --- a/src/friso_lexicon.c +++ b/src/friso_lexicon.c @@ -51,6 +51,10 @@ __STATIC_API__ void default_fdic_callback( hash_entry_t e ) } free_array_list( syn ); } + + //free the e->_val + //@date 2014-01-28 posted by mlemay@gmail.com + FRISO_FREE(lex); } FRISO_API void friso_dic_free( friso_dic_t dic ) @@ -300,7 +304,11 @@ FRISO_API void friso_dic_load( * and __LEX_CEM_WORDS__. */ if ( ! ( lex == __LEX_ECM_WORDS__ || lex == __LEX_CEM_WORDS__ ) - && strlen( _word ) > length ) continue; + && strlen( _word ) > length ) + { + FRISO_FREE(_word); + continue; + } //2. get the synonyms words. _syn = NULL;