summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2012-06-26 13:48:36 +0200
committerMichael Adam <obnox@samba.org>2012-06-29 15:21:10 +0200
commit3c3ed706908022ef26b5889971c4ec5040697f95 (patch)
treec84bcc5d65efd0dc4a6bd3936f53f2f9e37c1368 /lib
parent1a622fe641ffebd93a2ae1ee6ff5e8c4177668aa (diff)
downloadsamba-3c3ed706908022ef26b5889971c4ec5040697f95.tar.gz
samba-3c3ed706908022ef26b5889971c4ec5040697f95.tar.bz2
samba-3c3ed706908022ef26b5889971c4ec5040697f95.zip
lib/util: fix fd leak in anonymous_shared_allocate() if MAP_ANON is not available
metze
Diffstat (limited to 'lib')
-rw-r--r--lib/util/util.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/util/util.c b/lib/util/util.c
index 20466b41b3..100d3d84ab 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -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) {