Commit 32237e59 authored by Mathis Rosenhauer's avatar Mathis Rosenhauer

fixed some leaks and mem errors

parent 8fd6570e
CC = gcc CC = gcc
#CFLAGS = -g -pg -lc -O2 -Wall -fprofile-arcs -ftest-coverage -DPROFILE #CFLAGS = -g -pg -lc -O2 -Wall -fprofile-arcs -ftest-coverage -DPROFILE
CFLAGS = -g -pg -lc -O2 -Wall -fprofile-arcs -ftest-coverage -DUNROLL_BLOCK_8 #CFLAGS = -g -pg -lc -O2 -Wall -fprofile-arcs -ftest-coverage -DUNROLL_BLOCK_8
#CFLAGS = -g -O3 -Wall -DUNROLL_BLOCK_8 CFLAGS = -g -O3 -Wall -DUNROLL_BLOCK_8
OBJS = aee.o aed.o sz_compat.o OBJS = aee.o aed.o sz_compat.o
......
...@@ -326,6 +326,17 @@ int ae_decode_init(ae_streamp strm) ...@@ -326,6 +326,17 @@ int ae_decode_init(ae_streamp strm)
return AE_OK; return AE_OK;
} }
int ae_decode_end(ae_streamp strm)
{
decode_state *state;
state = strm->state;
free(state->block);
free(state->id_table);
free(state);
return AE_OK;
}
#define ASK(n) \ #define ASK(n) \
do { \ do { \
while (state->bitp < (unsigned)(n)) \ while (state->bitp < (unsigned)(n)) \
...@@ -426,7 +437,7 @@ int ae_decode(ae_streamp strm, int flush) ...@@ -426,7 +437,7 @@ int ae_decode(ae_streamp strm, int flush)
state->n = strm->block_size; state->n = strm->block_size;
} }
state->i = state->n; state->i = state->n - 1;
state->mode = M_SPLIT_FS; state->mode = M_SPLIT_FS;
case M_SPLIT_FS: case M_SPLIT_FS:
...@@ -436,9 +447,9 @@ int ae_decode(ae_streamp strm, int flush) ...@@ -436,9 +447,9 @@ int ae_decode(ae_streamp strm, int flush)
state->block[state->i] = GETFS(); state->block[state->i] = GETFS();
DROPFS(); DROPFS();
} }
while(--state->i); while(state->i--);
state->i = state->n; state->i = state->n - 1;
state->mode = M_SPLIT_OUTPUT; state->mode = M_SPLIT_OUTPUT;
case M_SPLIT_OUTPUT: case M_SPLIT_OUTPUT:
...@@ -449,7 +460,7 @@ int ae_decode(ae_streamp strm, int flush) ...@@ -449,7 +460,7 @@ int ae_decode(ae_streamp strm, int flush)
PUT((state->block[state->i] << k) + GET(k)); PUT((state->block[state->i] << k) + GET(k));
DROP(k); DROP(k);
} }
while(--state->i); while(state->i--);
state->mode = M_ID; state->mode = M_ID;
break; break;
......
...@@ -206,6 +206,20 @@ int ae_encode_init(ae_streamp strm) ...@@ -206,6 +206,20 @@ int ae_encode_init(ae_streamp strm)
return AE_OK; return AE_OK;
} }
int ae_encode_end(ae_streamp strm)
{
encode_state *state;
state = strm->state;
#ifdef PROFILE
free(state->prof);
#endif
free(state->block_in);
free(state->block_out);
free(state);
return AE_OK;
}
static inline void emit(encode_state *state, int64_t data, int bits) static inline void emit(encode_state *state, int64_t data, int bits)
{ {
while(bits) while(bits)
...@@ -595,14 +609,5 @@ int ae_encode(ae_streamp strm, int flush) ...@@ -595,14 +609,5 @@ int ae_encode(ae_streamp strm, int flush)
req_buffer: req_buffer:
strm->total_out = total_out; strm->total_out = total_out;
strm->avail_out = avail_out; strm->avail_out = avail_out;
if (strm->avail_in == 0 && avail_out && flush == AE_FLUSH)
{
#ifdef PROFILE
free(state->prof);
#endif
free(state->block_in);
free(state->block_out);
free(strm->state);
}
return AE_OK; return AE_OK;
} }
...@@ -59,8 +59,10 @@ typedef ae_stream *ae_streamp; ...@@ -59,8 +59,10 @@ typedef ae_stream *ae_streamp;
int ae_decode_init(ae_streamp strm); int ae_decode_init(ae_streamp strm);
int ae_decode(ae_streamp strm, int flush); int ae_decode(ae_streamp strm, int flush);
int ae_decode_end(ae_streamp strm);
int ae_encode_init(ae_streamp strm); int ae_encode_init(ae_streamp strm);
int ae_encode(ae_streamp strm, int flush); int ae_encode(ae_streamp strm, int flush);
int ae_encode_end(ae_streamp strm);
#endif /* LIBAE_H */ #endif /* LIBAE_H */
...@@ -21,6 +21,9 @@ int SZ_BufftoBuffCompress(void *dest, size_t *destLen, const void *source, size_ ...@@ -21,6 +21,9 @@ int SZ_BufftoBuffCompress(void *dest, size_t *destLen, const void *source, size_
if ((status = ae_encode(&strm, AE_FLUSH)) != AE_OK) if ((status = ae_encode(&strm, AE_FLUSH)) != AE_OK)
return status; return status;
if ((status = ae_encode_end(&strm)) != AE_OK)
return status;
*destLen = strm.total_out; *destLen = strm.total_out;
return SZ_OK; return SZ_OK;
} }
...@@ -45,6 +48,9 @@ int SZ_BufftoBuffDecompress(void *dest, size_t *destLen, const void *source, siz ...@@ -45,6 +48,9 @@ int SZ_BufftoBuffDecompress(void *dest, size_t *destLen, const void *source, siz
if ((status = ae_decode(&strm, AE_FLUSH)) != AE_OK) if ((status = ae_decode(&strm, AE_FLUSH)) != AE_OK)
return status; return status;
if ((status = ae_decode_end(&strm)) != AE_OK)
return status;
*destLen = strm.total_out; *destLen = strm.total_out;
return SZ_OK; return SZ_OK;
} }
...@@ -88,5 +88,8 @@ int main(int argc, char *argv[]) ...@@ -88,5 +88,8 @@ int main(int argc, char *argv[])
} }
ae_decode_end(&strm);
free(in);
free(out);
return 0; return 0;
} }
...@@ -105,5 +105,8 @@ int main(int argc, char *argv[]) ...@@ -105,5 +105,8 @@ int main(int argc, char *argv[])
putc(out[i], stdout); putc(out[i], stdout);
} }
} }
ae_encode_end(&strm);
free(in);
free(out);
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 to comment