diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index d7e7bfc0878e..591094e5af96 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -1740,16 +1740,16 @@ __elfN(note_threadmd)(void *arg, struct sbuf *sb, size_t *sizep) td = (struct thread *)arg; size = *sizep; - buf = NULL; if (size != 0 && sb != NULL) buf = malloc(size, M_TEMP, M_ZERO | M_WAITOK); + else + buf = NULL; size = 0; __elfN(dump_thread)(td, buf, &size); KASSERT(*sizep == size, ("invalid size")); - if (size != 0 && sb != NULL) { + if (size != 0 && sb != NULL) sbuf_bcat(sb, buf, size); - free(buf, M_TEMP); - } + free(buf, M_TEMP); *sizep = size; }