X-Git-Url: https://git.llucax.com/z.facultad/75.06/jacu.git/blobdiff_plain/20b0b8b6db70b1a0c9b4c211f43e91562af6c54c..7a58d786d9ca645f1e61a5cb4128f354ae7a80ef:/src/statichuff/statichuff.c diff --git a/src/statichuff/statichuff.c b/src/statichuff/statichuff.c index 797ca17..9168919 100644 --- a/src/statichuff/statichuff.c +++ b/src/statichuff/statichuff.c @@ -50,6 +50,21 @@ int shuff_compnode(const void *node1, const void *node2) return 0; } +void shuff_destroy_tree(SHUFFNODE *node) { + /* Si llegue a una hoja, destruyo y vuelvo */ + if (node->symbol < 256) { + free(node); + return; + } + else { + /* Desciendo por izq, luego por derecha y luego libero */ + shuff_destroy_tree(node->lchild); + shuff_destroy_tree(node->rchild); + free(node); + return; + } +} + int shuff_rescalefreq(t_freq *freqtable) { int i; @@ -509,6 +524,7 @@ void shuff_deinit_encoder(HUFF_STATE *shuff) if (shuff->targetfile) free(shuff->targetfile); /* Destruyo recursivamente el arbol de codigos */ + if (shuff->codetree) shuff_destroy_tree(shuff->codetree); } void shuff_deinit_decoder(HUFF_STATE *shuff) @@ -520,4 +536,5 @@ void shuff_deinit_decoder(HUFF_STATE *shuff) if (shuff->decoderfp != NULL) vfclose(shuff->decoderfp); /* Destruyo recursivamente el arbol de codigos */ + if (shuff->codetree) shuff_destroy_tree(shuff->codetree); }