[PATCH] mmap error handling
I have reviewed all occurrences of mmap() in git and fixed three types of errors/defects: 1) The result is not checked. 2) The file descriptor is closed if mmap() succeeds, but not when it fails. 3) Various casts applied to -1 are used instead of MAP_FAILED, which is specifically defined to check mmap() return value. [jc: This is a second round of Pavel's patch. He fixed up the problem that close() potentially clobbering the errno from mmap, which the first round had.] Signed-off-by: Pavel Roskin <proski@gnu.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:

committed by
Junio C Hamano

parent
1df092d211
commit
e35f982415
@ -41,6 +41,7 @@ int main(int argc, char *argv[])
|
||||
from_buf = mmap(NULL, from_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
if (from_buf == MAP_FAILED) {
|
||||
perror(argv[2]);
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
close(fd);
|
||||
@ -54,6 +55,7 @@ int main(int argc, char *argv[])
|
||||
data_buf = mmap(NULL, data_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
if (data_buf == MAP_FAILED) {
|
||||
perror(argv[3]);
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
close(fd);
|
||||
|
Reference in New Issue
Block a user