Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Rudolf
/
huffman
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
cb84a6fd
authored
Nov 17, 2016
by
Rudolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix memory leakage by freeing tree when decoding
Also adjust some spaces and whatnot.
parent
fc7e2827
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
huffman.c
huffman.c
View file @
cb84a6fd
...
...
@@ -62,6 +62,7 @@ int encode_file(FILE *in, FILE *out)
fseek
(
in
,
0
,
SEEK_SET
);
char
*
buf
=
read_text
(
in
,
size
);
encode_tree
(
&
bitbuf
,
tree
,
buf
,
size
);
free
(
buf
);
...
...
@@ -72,20 +73,19 @@ int encode_file(FILE *in, FILE *out)
int
decode_file
(
FILE
*
in
,
FILE
*
out
)
{
struct
tree
*
tree
=
malloc
(
sizeof
(
*
tree
));
struct
BIT_BUFFER
bitbuf
;
bb_init
(
&
bitbuf
,
in
);
struct
tree
*
decoded
=
malloc
(
sizeof
(
*
decoded
));
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
)
print_tree
(
decoded
);
print_tree
(
tree
);
free
(
decoded
);
free
_tree
(
tree
);
return
0
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment