diff options
Diffstat (limited to 'xzlib.c')
-rw-r--r-- | xzlib.c | 28 |
1 files changed, 15 insertions, 13 deletions
@@ -31,10 +31,10 @@ #ifdef HAVE_STDLIB_H #include <stdlib.h> #endif -#ifdef HAVE_ZLIB_H +#ifdef LIBXML_ZLIB_ENABLED #include <zlib.h> #endif -#ifdef HAVE_LZMA_H +#ifdef LIBXML_LZMA_ENABLED #include <lzma.h> #endif @@ -76,7 +76,7 @@ typedef struct { char padding1[32]; /* padding allowing to cope with possible extensions of above structure without too much side effect */ -#ifdef HAVE_ZLIB_H +#ifdef LIBXML_ZLIB_ENABLED /* zlib inflate or deflate stream */ z_stream zstrm; /* stream structure in-place (not a pointer) */ #endif @@ -130,7 +130,7 @@ xz_reset(xz_statep state) xz_error(state, LZMA_OK, NULL); /* clear error */ state->pos = 0; /* no uncompressed data yet */ state->strm.avail_in = 0; /* no input data yet */ -#ifdef HAVE_ZLIB_H +#ifdef LIBXML_ZLIB_ENABLED state->zstrm.avail_in = 0; /* no input data yet */ #endif } @@ -272,7 +272,7 @@ xz_avail(xz_statep state) return 0; } -#ifdef HAVE_ZLIB_H +#ifdef LIBXML_ZLIB_ENABLED static int xz_avail_zstrm(xz_statep state) { @@ -349,7 +349,7 @@ is_format_lzma(xz_statep state) return 1; } -#ifdef HAVE_ZLIB_H +#ifdef LIBXML_ZLIB_ENABLED /* Get next byte from input, or -1 if end or error. */ #define NEXT() ((strm->avail_in == 0 && xz_avail(state) == -1) ? -1 : \ @@ -408,14 +408,14 @@ xz_head(xz_statep state) state->strm = init; state->strm.avail_in = 0; state->strm.next_in = NULL; - if (lzma_auto_decoder(&state->strm, UINT64_MAX, 0) != LZMA_OK) { + if (lzma_auto_decoder(&state->strm, 100000000, 0) != LZMA_OK) { xmlFree(state->out); xmlFree(state->in); state->size = 0; xz_error(state, LZMA_MEM_ERROR, "out of memory"); return -1; } -#ifdef HAVE_ZLIB_H +#ifdef LIBXML_ZLIB_ENABLED /* allocate inflate memory */ state->zstrm.zalloc = Z_NULL; state->zstrm.zfree = Z_NULL; @@ -449,7 +449,7 @@ xz_head(xz_statep state) state->direct = 0; return 0; } -#ifdef HAVE_ZLIB_H +#ifdef LIBXML_ZLIB_ENABLED /* look for the gzip magic header bytes 31 and 139 */ if (strm->next_in[0] == 31) { strm->avail_in--; @@ -550,7 +550,7 @@ xz_decomp(xz_statep state) action = LZMA_FINISH; /* decompress and handle errors */ -#ifdef HAVE_ZLIB_H +#ifdef LIBXML_ZLIB_ENABLED if (state->how == GZIP) { state->zstrm.avail_in = (uInt) state->strm.avail_in; state->zstrm.next_in = (Bytef *) state->strm.next_in; @@ -592,13 +592,13 @@ xz_decomp(xz_statep state) /* update available output and crc check value */ state->have = had - strm->avail_out; state->next = strm->next_out - state->have; -#ifdef HAVE_ZLIB_H +#ifdef LIBXML_ZLIB_ENABLED state->zstrm.adler = crc32(state->zstrm.adler, state->next, state->have); #endif if (ret == LZMA_STREAM_END) { -#ifdef HAVE_ZLIB_H +#ifdef LIBXML_ZLIB_ENABLED if (state->how == GZIP) { if (gz_next4(state, &crc) == -1 || gz_next4(state, &len) == -1) { xz_error(state, LZMA_DATA_ERROR, "unexpected end of file"); @@ -788,7 +788,7 @@ __libxml2_xzclose(xzFile file) /* free memory and close file */ if (state->size) { lzma_end(&(state->strm)); -#ifdef HAVE_ZLIB_H +#ifdef LIBXML_ZLIB_ENABLED if (state->init == 1) inflateEnd(&(state->zstrm)); state->init = 0; @@ -797,6 +797,8 @@ __libxml2_xzclose(xzFile file) xmlFree(state->in); } xmlFree(state->path); + if ((state->msg != NULL) && (state->err != LZMA_MEM_ERROR)) + xmlFree(state->msg); ret = close(state->fd); xmlFree(state); return ret ? ret : LZMA_OK; |