diff options
author | Stefan Metzmacher <metze@samba.org> | 2012-06-26 13:48:36 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2012-06-29 15:21:10 +0200 |
commit | 3c3ed706908022ef26b5889971c4ec5040697f95 (patch) | |
tree | c84bcc5d65efd0dc4a6bd3936f53f2f9e37c1368 | |
parent | 1a622fe641ffebd93a2ae1ee6ff5e8c4177668aa (diff) | |
download | samba-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
-rw-r--r-- | lib/util/util.c | 15 |
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) { |