libzfs: Do not call munmap() when mmap() fails

Reported-by: Grok 4.5 Build Beta
Reviewed-by: Igor Kozhukhov <[email protected]>
Reviewed-by: Rob Norris <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Alexander Motin <[email protected]>
Signed-off-by: Richard Yao <[email protected]>
Closes #18869
This commit is contained in:
Richard Yao authored and GitHub committed 2026-07-31 13:04:57 -07:00
1 parent b5bb1f8161
commit be62c53850
1 file changed
+3 -2
+3 -2
View File
@@ -5534,9 +5534,10 @@ zpool_load_compat(const char *compat, boolean_t *features, char *report,
ZC_MMAP_FLAGS, featfd, 0);
(void) close(featfd);
/* map ok, and last character == newline? */
/* need map ok, and last character == newline */
if (fc == MAP_FAILED || fc[fs.st_size - 1] != '\n') {
(void) munmap((void *) fc, fs.st_size);
if (fc != MAP_FAILED)
(void) munmap((void *) fc, fs.st_size);
strlcat(err_badfile, file, ZFS_MAXPROPLEN);
strlcat(err_badfile, " ", ZFS_MAXPROPLEN);
ret_badfile = B_TRUE;