shuff_deinit_encoder(shuff);
/* Free mem allocated by main */
- free(shuff);
- free(chunk);
+ free(shuff);
/* Close files opened by main */
fclose(fp);
/* Deinit decoder */
shuff_deinit_decoder(shuff);
- free(shuff);
+ free(shuff);
}
-
+
+ /* Free mem */
+ free(chunk);
return 0;
}
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;
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)
if (shuff->decoderfp != NULL) vfclose(shuff->decoderfp);
/* Destruyo recursivamente el arbol de codigos */
+ if (shuff->codetree) shuff_destroy_tree(shuff->codetree);
}