--- pgp/src/zdeflate.c 2018/04/24 16:38:50 1.1.1.2 +++ pgp/src/zdeflate.c 2018/04/24 16:39:33 1.1.1.3 @@ -68,6 +68,7 @@ * attributes. */ +#include "zunzip.h" #include "zip.h" /* =========================================================================== @@ -140,7 +141,7 @@ typedef unsigned IPos; #else uch far * near window = NULL; Pos far * near prev = NULL; - Pos far * near head; + static Pos far * near head; #endif long block_start; @@ -163,7 +164,7 @@ unsigned int near prev_length; */ unsigned near strstart; /* start of string to insert */ - unsigned near match_start; /* start of matching string */ +unsigned near match_start; /* start of matching string */ local int near eofile; /* flag set at end of input file */ local unsigned near lookahead; /* number of valid bytes ahead in window */ @@ -235,6 +236,7 @@ local void fill_window OF((void)); local void check_match OF((IPos start, IPos match, int length)); #endif +#undef MIN #define MIN(a,b) ((a) <= (b) ? (a) : (b)) /* The arguments must not have side effects. */ @@ -272,15 +274,13 @@ void lm_init (pack_level, flags) /* Use dynamic allocation if compiler does not like big static arrays: */ #ifdef DYN_ALLOC - if (window == NULL) { - window = (uch far*) fcalloc(WSIZE, 2*sizeof(uch)); - prev = (Pos far*) fcalloc(WSIZE, sizeof(Pos)); - head = (Pos far*) fcalloc(HASH_SIZE, sizeof(Pos)); - - if (window == NULL || prev == NULL || head == NULL) { - err(ZE_MEM, "window allocation"); - } - } + window = (uch far*) fcalloc(WSIZE, 2*sizeof(uch)); + prev = (Pos far*) fcalloc(WSIZE, sizeof(Pos)); + head = (Pos far*) fcalloc(HASH_SIZE, sizeof(Pos)); + + if (window == NULL || prev == NULL || head == NULL) { + err(ZE_MEM, "window allocation"); + } #endif /* DYN_ALLOC */ #ifdef ASM match_init(); /* initialize the asm code */ @@ -323,6 +323,17 @@ void lm_init (pack_level, flags) */ } +void lm_free() +{ +#ifdef DYN_ALLOC + free(window); + free(prev); + free(head); + window = NULL; + prev = head = NULL; +#endif +} + /* =========================================================================== * Set match_start to the longest match starting at the given string and * return its length. Matches shorter or equal to prev_length are discarded,