Commit cb84a6fd by Rudolf

Fix memory leakage by freeing tree when decoding

Also adjust some spaces and whatnot.
parent fc7e2827
Showing with 6 additions and 6 deletions
...@@ -62,6 +62,7 @@ int encode_file(FILE *in, FILE *out) ...@@ -62,6 +62,7 @@ int encode_file(FILE *in, FILE *out)
fseek(in, 0, SEEK_SET); fseek(in, 0, SEEK_SET);
char *buf = read_text(in, size); char *buf = read_text(in, size);
encode_tree(&bitbuf, tree, buf, size); encode_tree(&bitbuf, tree, buf, size);
free(buf); free(buf);
...@@ -72,20 +73,19 @@ int encode_file(FILE *in, FILE *out) ...@@ -72,20 +73,19 @@ int encode_file(FILE *in, FILE *out)
int decode_file(FILE *in, FILE *out) int decode_file(FILE *in, FILE *out)
{ {
struct tree *tree = malloc(sizeof(*tree));
struct BIT_BUFFER bitbuf; struct BIT_BUFFER bitbuf;
bb_init(&bitbuf, in); bb_init(&bitbuf, in);
struct tree *decoded = malloc(sizeof(*decoded));
fseek(in, 0, SEEK_SET); fseek(in, 0, SEEK_SET);
decode_header(&bitbuf, decoded); decode_header(&bitbuf, tree);
decode_tree(&bitbuf, out, decoded); decode_tree(&bitbuf, out, tree);
if (DEBUG) if (DEBUG)
print_tree(decoded); print_tree(tree);
free(decoded); free_tree(tree);
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment