@@ -273,7 +273,7 @@ void openblas_fork_handler()
273273}
274274
275275int blas_get_cpu_number (void ){
276- char * p ;
276+ env_var_t p ;
277277#if defined(OS_LINUX ) || defined(OS_WINDOWS ) || defined(OS_FREEBSD ) || defined(OS_DARWIN )
278278 int max_num ;
279279#endif
@@ -288,21 +288,18 @@ int blas_get_cpu_number(void){
288288
289289 blas_goto_num = 0 ;
290290#ifndef USE_OPENMP
291- p = getenv ("OPENBLAS_NUM_THREADS" );
292- if (p ) blas_goto_num = atoi (p );
291+ if (readenv (p ,"OPENBLAS_NUM_THREADS" )) blas_goto_num = atoi (p );
293292 if (blas_goto_num < 0 ) blas_goto_num = 0 ;
294293
295294 if (blas_goto_num == 0 ) {
296- p = getenv ("GOTO_NUM_THREADS" );
297- if (p ) blas_goto_num = atoi (p );
295+ if (readenv (p ,"GOTO_NUM_THREADS" )) blas_goto_num = atoi (p );
298296 if (blas_goto_num < 0 ) blas_goto_num = 0 ;
299297 }
300298
301299#endif
302300
303301 blas_omp_num = 0 ;
304- p = getenv ("OMP_NUM_THREADS" );
305- if (p ) blas_omp_num = atoi (p );
302+ if (readenv (p ,"OMP_NUM_THREADS" )) blas_omp_num = atoi (p );
306303 if (blas_omp_num < 0 ) blas_omp_num = 0 ;
307304
308305 if (blas_goto_num > 0 ) blas_num_threads = blas_goto_num ;
@@ -769,16 +766,23 @@ static void *alloc_hugetlb(void *address){
769766 tp .PrivilegeCount = 1 ;
770767 tp .Privileges [0 ].Attributes = SE_PRIVILEGE_ENABLED ;
771768
772- if (LookupPrivilegeValue (NULL , SE_LOCK_MEMORY_NAME , & tp .Privileges [0 ].Luid ) != TRUE) return (void * ) -1 ;
769+ if (LookupPrivilegeValue (NULL , SE_LOCK_MEMORY_NAME , & tp .Privileges [0 ].Luid ) != TRUE) {
770+ CloseHandle (hToken );
771+ return -1 ;
772+ }
773773
774- if (AdjustTokenPrivileges (hToken , FALSE, (PTOKEN_PRIVILEGES )& tp , 0 , NULL , NULL ) != TRUE) return (void * ) -1 ;
774+ if (AdjustTokenPrivileges (hToken , FALSE, & tp , 0 , NULL , NULL ) != TRUE) {
775+ CloseHandle (hToken );
776+ return -1 ;
777+ }
775778
776779 map_address = (void * )VirtualAlloc (address ,
777780 BUFFER_SIZE ,
778781 MEM_LARGE_PAGES | MEM_RESERVE | MEM_COMMIT ,
779782 PAGE_READWRITE );
780783
781- AdjustTokenPrivileges (hToken , TRUE, & tp , 0 , (PTOKEN_PRIVILEGES )NULL , NULL );
784+ tp .Privileges [0 ].Attributes = 0 ;
785+ AdjustTokenPrivileges (hToken , FALSE, & tp , 0 , NULL , NULL );
782786
783787 if (map_address == (void * )NULL ) map_address = (void * )-1 ;
784788
0 commit comments