diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index 067512831e3e..cfe5f109b705 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -1241,6 +1241,7 @@ __elfN(coredump)(struct thread *td, struct vnode *vp, off_t limit, int flags) compress = (flags & IMGACT_CORE_COMPRESS) != 0; hdr = NULL; + tmpbuf = NULL; TAILQ_INIT(¬elst); /* Size the program segments. */ @@ -1255,6 +1256,14 @@ __elfN(coredump)(struct thread *td, struct vnode *vp, off_t limit, int flags) __elfN(prepare_notes)(td, ¬elst, ¬esz); coresize = round_page(hdrsize + notesz) + seginfo.size; + /* Set up core dump parameters. */ + params.offset = 0; + params.active_cred = cred; + params.file_cred = NOCRED; + params.td = td; + params.vp = vp; + params.gzs = NULL; + #ifdef RACCT if (racct_enable) { PROC_LOCK(td->td_proc); @@ -1271,15 +1280,6 @@ __elfN(coredump)(struct thread *td, struct vnode *vp, off_t limit, int flags) goto done; } - /* Set up core dump parameters. */ - params.offset = 0; - params.active_cred = cred; - params.file_cred = NOCRED; - params.td = td; - params.vp = vp; - params.gzs = NULL; - - tmpbuf = NULL; #ifdef GZIO /* Create a compression stream if necessary. */ if (compress) { @@ -1336,7 +1336,8 @@ __elfN(coredump)(struct thread *td, struct vnode *vp, off_t limit, int flags) #ifdef GZIO if (compress) { free(tmpbuf, M_TEMP); - gzio_fini(params.gzs); + if (params.gzs != NULL) + gzio_fini(params.gzs); } #endif while ((ninfo = TAILQ_FIRST(¬elst)) != NULL) {