aboutsummaryrefslogtreecommitdiffhomepage
path: root/linux
diff options
context:
space:
mode:
authorGravatar jkeil <jkeil@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-07-19 20:32:13 +0000
committerGravatar jkeil <jkeil@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-07-19 20:32:13 +0000
commit8c734ab19ff2456e2f893fbedcfc83848f529e21 (patch)
treeaf71f5f4779e2f41c84a03f322a530aa6551b254 /linux
parent42805cb4512f1edd857564092ca812d9c5065b95 (diff)
Solaris 2.6 and older do not support MAP_ANON, just fail the mmap MAP_ANON
attempt on such a system. The code tries mmap with /dev/zero and MIT-shm next. Fix a possible filedesc leak, when the code tries to mmap shared memeory via /dev/zero. Reuse the already open /dev/zero from a previous shmem_alloc call. (same change; now without changing the indentation of the code) git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@1348 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'linux')
-rw-r--r--linux/shmem.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/linux/shmem.c b/linux/shmem.c
index 73b084ddb2..6cdf108c80 100644
--- a/linux/shmem.c
+++ b/linux/shmem.c
@@ -35,16 +35,21 @@ static int shmem_type=0;
void* shmem_alloc(int size){
void* p;
-int devzero;
+static int devzero = -1;
while(1){
switch(shmem_type){
case 0: // ========= MAP_ANON|MAP_SHARED ==========
+#ifdef MAP_ANON
p=mmap(0,size,PROT_READ|PROT_WRITE,MAP_ANON|MAP_SHARED,-1,0);
if(p==MAP_FAILED) break; // failed
// printf("shmem: %d bytes allocated using mmap anon (%X)\n",size,p);
return p;
+#else
+// system does not support MAP_ANON at all (e.g. solaris 2.5.1/2.6), just fail
+ break;
+#endif
case 1: // ========= MAP_SHARED + /dev/zero ==========
- if ((devzero = open("/dev/zero", O_RDWR, 0)) == -1) break;
+ if (devzero == -1 && (devzero = open("/dev/zero", O_RDWR, 0)) == -1) break;
p=mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,devzero,0);
if(p==MAP_FAILED) break; // failed
// printf("shmem: %d bytes allocated using mmap /dev/zero (%X)\n",size,p);