]> git.llucax.com Git - z.facultad/75.06/jacu.git/commitdiff
Zero Leaks
authorAlan Kennedy <kennedya@3dgames.com.ar>
Sun, 27 Jun 2004 03:59:51 +0000 (03:59 +0000)
committerAlan Kennedy <kennedya@3dgames.com.ar>
Sun, 27 Jun 2004 03:59:51 +0000 (03:59 +0000)
src/statichuff/main_bychunk.c
src/statichuff/statichuff.c

index f2fca8678b8ce371aa8538e8c9c221d97a2146c1..e0f1e2850601f4d4a9f6b436cee2f8046c872023 100644 (file)
@@ -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;
 }
index 797ca1723446bf4eee23d9cf60d35649eb760caa..916891966611f46a32409f3b11e88df24d0cf3e6 100644 (file)
@@ -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);
 }