Mercurial > mplayer.hg
changeset 1347:448d1bf28f5a
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)
author | jkeil |
---|---|
date | Thu, 19 Jul 2001 20:32:13 +0000 |
parents | d6e6132bff35 |
children | e7778832010d |
files | linux/shmem.c |
diffstat | 1 files changed, 7 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/linux/shmem.c Thu Jul 19 20:04:54 2001 +0000 +++ b/linux/shmem.c Thu Jul 19 20:32:13 2001 +0000 @@ -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);