From: Alan Kennedy Date: Sun, 27 Jun 2004 03:59:51 +0000 (+0000) Subject: Zero Leaks X-Git-Tag: svn_import~37 X-Git-Url: https://git.llucax.com/z.facultad/75.06/jacu.git/commitdiff_plain/7a58d786d9ca645f1e61a5cb4128f354ae7a80ef Zero Leaks --- diff --git a/src/statichuff/main_bychunk.c b/src/statichuff/main_bychunk.c index f2fca86..e0f1e28 100644 --- a/src/statichuff/main_bychunk.c +++ b/src/statichuff/main_bychunk.c @@ -74,8 +74,7 @@ int main(int argc, char* argv[]) shuff_deinit_encoder(shuff); /* Free mem allocated by main */ - free(shuff); - free(chunk); + free(shuff); /* Close files opened by main */ fclose(fp); @@ -96,8 +95,10 @@ int main(int argc, char* argv[]) /* Deinit decoder */ shuff_deinit_decoder(shuff); - free(shuff); + free(shuff); } - + + /* Free mem */ + free(chunk); return 0; } 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); }