When fill2 fails to open the output file (e.g. due to ENOSPC), it jumps
into the cleanup code where it attempts to call fclose, and this causes
a segfault within the glibc fclose code as it attempts to deref a null
pointer.
Fix it by conditionally calling fclose on the file pointer only when
non-null.
This is consistently reproducible with xfs/041.
Signed-off-by: Anthony Iliopoulos <ailiop@suse.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
cleanup:
/* close file and flush buffers - check if this fails */
- if (fclose(f) != 0) {
+ if (f && fclose(f) != 0) {
fprintf(stderr, "fill2: fclose() on \"%s\" failed: %s\n",
dfile, strerror(errno));
status = 1;