1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

lib/util: fix fd leak in anonymous_shared_allocate() if MAP_ANON is not available

metze
This commit is contained in:
Stefan Metzmacher 2012-06-26 13:48:36 +02:00 committed by Michael Adam
parent 1a622fe641
commit 3c3ed70690

View File

@ -1109,8 +1109,21 @@ void *anonymous_shared_allocate(size_t orig_bufsz)
buf = mmap(NULL, bufsz, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED,
-1 /* fd */, 0 /* offset */);
#else
{
int saved_errno;
int fd;
fd = open("/dev/zero", O_RDWR);
if (fd == -1) {
return NULL;
}
buf = mmap(NULL, bufsz, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED,
open("/dev/zero", O_RDWR), 0 /* offset */);
fd, 0 /* offset */);
saved_errno = errno;
close(fd);
errno = saved_errno;
}
#endif
if (buf == MAP_FAILED) {