mirror of https://github.com/mpv-player/mpv
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
This commit is contained in:
parent
42805cb451
commit
8c734ab19f
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue