[Mplayer-cvslog] CVS: main/linux shmem.c,1.2,1.3

Jürgen Keil jkeil at mplayer.dev.hu
Thu Jul 19 22:32:16 CEST 2001


Update of /cvsroot/mplayer/main/linux
In directory mplayer:/var/tmp.root/cvs-serv4459

Modified Files:
	shmem.c 
Log Message:
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)


Index: shmem.c
===================================================================
RCS file: /cvsroot/mplayer/main/linux/shmem.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- shmem.c	18 Apr 2001 01:25:09 -0000	1.2
+++ shmem.c	19 Jul 2001 20:32:13 -0000	1.3
@@ -35,16 +35,21 @@
 
 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);




More information about the MPlayer-cvslog mailing list