Skip to content

Commit

Permalink
[ZTS] fclose in mmapwrite.c
Browse files Browse the repository at this point in the history
mmapwrite is used during the ZTS to identify issues with mmap-ed files.
This helper program exercises this pathway by continuously writing to a
file.  ee6bf97 modified the writing threads to terminate after a set
amount of total data is written.  This change allows standard program
execution to reach the end of a writer thread without closing the file
descriptor, introducing a resource "leak."

This patch appeases resource leak analyses by fclose()-ing the file at
the end of the thread.  It also cleans up some error handling.

Signed-off-by: Antonio Russo <aerusso@aerusso.net>
  • Loading branch information
aerusso committed Jan 6, 2023
1 parent ee6bf97 commit 9246e01
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/zfs-tests/cmd/mmapwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ normal_writer(void *filename)
fd = open(file_path, O_RDWR | O_CREAT, 0777);
if (fd == -1) {
err(1, "failed to open %s", file_path);
return (NULL);
}

char buf = 'z';
Expand All @@ -82,6 +83,10 @@ normal_writer(void *filename)
break;
}
}

if (fclose(fd) != 0)
err(1, "failed to close file");

return (NULL);
}

Expand Down

0 comments on commit 9246e01

Please sign in to comment.