instead of malloc, this also enforces data alignment.
*/
#include "zbuild.h"
+#include "zutil_p.h"
#include "gzguts.h"
#if defined(_WIN32)
return NULL;
/* allocate gzFile structure to return */
- state = (gz_state *)malloc(sizeof(gz_state));
+ state = (gz_state *)zng_alloc(sizeof(gz_state));
if (state == NULL)
return NULL;
state->size = 0; /* no buffers allocated yet */
break;
#endif
case '+': /* can't read and write at the same time */
- free(state);
+ zng_free(state);
return NULL;
case 'b': /* ignore -- will request binary anyway */
break;
/* must provide an "r", "w", or "a" */
if (state->mode == GZ_NONE) {
- free(state);
+ zng_free(state);
return NULL;
}
/* can't force transparent read */
if (state->mode == GZ_READ) {
if (state->direct) {
- free(state);
+ zng_free(state);
return NULL;
}
state->direct = 1; /* for empty file */
len = strlen((const char *)path);
state->path = (char *)malloc(len + 1);
if (state->path == NULL) {
- free(state);
+ zng_free(state);
return NULL;
}
#ifdef WIDECHAR
open((const char *)path, oflag, 0666));
if (state->fd == -1) {
free(state->path);
- free(state);
+ zng_free(state);
return NULL;
}
if (state->mode == GZ_APPEND) {
*/
#include "zbuild.h"
+#include "zutil_p.h"
#include "gzguts.h"
/* Local functions */
/* 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;
}
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;
/* 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;
}
*/
#include "zbuild.h"
+#include "zutil_p.h"
#include <stdarg.h>
#include "gzguts.h"
PREFIX3(stream) *strm = &(state->strm);
/* allocate input buffer (double size for gzprintf) */
- state->in = (unsigned char *)malloc(state->want << 1);
+ state->in = (unsigned char *)zng_alloc(state->want << 1);
if (state->in == NULL) {
gz_error(state, Z_MEM_ERROR, "out of memory");
return -1;
/* only need output buffer and deflate state if compressing */
if (!state->direct) {
/* allocate output buffer */
- state->out = (unsigned char *)malloc(state->want);
+ state->out = (unsigned char *)zng_alloc(state->want);
if (state->out == NULL) {
- free(state->in);
+ zng_free(state->in);
gz_error(state, Z_MEM_ERROR, "out of memory");
return -1;
}
strm->opaque = NULL;
ret = PREFIX(deflateInit2)(strm, state->level, Z_DEFLATED, MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
if (ret != Z_OK) {
- 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;
}
if (state->size) {
if (!state->direct) {
(void)PREFIX(deflateEnd)(&(state->strm));
- free(state->out);
+ zng_free(state->out);
}
- free(state->in);
+ zng_free(state->in);
}
gz_error(state, Z_OK, NULL);
free(state->path);
if (close(state->fd) == -1)
ret = Z_ERRNO;
- free(state);
+ zng_free(state);
return ret;
}