summaryrefslogtreecommitdiff
path: root/gzread.c
diff options
context:
space:
mode:
authorHans Kristian Rosbach <hk-git@circlestorm.org>2020-09-12 23:18:13 +0200
committerHans Kristian Rosbach <hk-github@circlestorm.org>2020-09-14 12:04:30 +0200
commita14ec1a53ad28277641b1dec5fe8f4a5568fb040 (patch)
tree50ec1d04c9ec9304dacbdf1d57b8843a4f94ae86 /gzread.c
parent2cc497634714cb1a4c1e4b9fcdcb366f4e41fd6a (diff)
Allocate gzlib/gzread/gzwrite structs and in/out buffers using zng_alloc
instead of malloc, this also enforces data alignment.
Diffstat (limited to 'gzread.c')
-rw-r--r--gzread.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/gzread.c b/gzread.c
index 7d05f75..e487d99 100644
--- a/gzread.c
+++ b/gzread.c
@@ -4,6 +4,7 @@
*/
#include "zbuild.h"
+#include "zutil_p.h"
#include "gzguts.h"
/* Local functions */
@@ -83,11 +84,11 @@ static int gz_look(gz_state *state) {
/* allocate read buffers and inflate memory */
if (state->size == 0) {
/* allocate buffers */
- state->in = (unsigned char *)malloc(state->want);
- state->out = (unsigned char *)malloc(state->want << 1);
+ state->in = (unsigned char *)zng_alloc(state->want);
+ state->out = (unsigned char *)zng_alloc(state->want << 1);
if (state->in == NULL || state->out == NULL) {
- free(state->out);
- free(state->in);
+ zng_free(state->out);
+ zng_free(state->in);
gz_error(state, Z_MEM_ERROR, "out of memory");
return -1;
}
@@ -100,8 +101,8 @@ static int gz_look(gz_state *state) {
state->strm.avail_in = 0;
state->strm.next_in = NULL;
if (PREFIX(inflateInit2)(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */
- free(state->out);
- free(state->in);
+ zng_free(state->out);
+ zng_free(state->in);
state->size = 0;
gz_error(state, Z_MEM_ERROR, "out of memory");
return -1;
@@ -589,13 +590,13 @@ int Z_EXPORT PREFIX(gzclose_r)(gzFile file) {
/* free memory and close file */
if (state->size) {
PREFIX(inflateEnd)(&(state->strm));
- free(state->out);
- free(state->in);
+ zng_free(state->out);
+ zng_free(state->in);
}
err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
gz_error(state, Z_OK, NULL);
free(state->path);
ret = close(state->fd);
- free(state);
+ zng_free(state);
return ret ? Z_ERRNO : err;
}