From 67cc20d0041a32bee12bd9eb20ae218f91b73f77 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Fri, 9 Sep 2011 23:32:36 -0700 Subject: zlib 1.2.4-pre1 --- gzlib.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'gzlib.c') diff --git a/gzlib.c b/gzlib.c index 03240b1..6fdb08a 100644 --- a/gzlib.c +++ b/gzlib.c @@ -147,6 +147,14 @@ local gzFile gz_open(path, fd, mode) return NULL; } + /* save the path name for error messages */ + state->path = malloc(strlen(path) + 1); + if (state->path == NULL) { + free(state); + return NULL; + } + strcpy(state->path, path); + /* open the file with the appropriate mode (or just use fd) */ state->fd = fd != -1 ? fd : open(path, @@ -170,14 +178,6 @@ local gzFile gz_open(path, fd, mode) if (state->mode == GZ_APPEND) state->mode = GZ_WRITE; /* simplify later checks */ - /* save the path name for error messages */ - state->path = malloc(strlen(path) + 1); - if (state->path == NULL) { - free(state); - return NULL; - } - strcpy(state->path, path); - /* save the current position for rewinding (only if reading) */ if (state->mode == GZ_READ) { state->start = LSEEK(state->fd, 0, SEEK_CUR); @@ -450,7 +450,8 @@ const char * ZEXPORT gzerror(file, errnum) return NULL; /* return error information */ - *errnum = state->err; + if (errnum != NULL) + *errnum = state->err; return state->msg == NULL ? "" : state->msg; } -- cgit v1.2.3-55-g6feb