@@ -409,10 +409,9 @@ pub unsafe fn environ() -> *mut *const *const c_char {
409409/// environment variables of the current process.
410410pub fn env ( ) -> Env {
411411 unsafe {
412- ENV_LOCK . lock ( ) ;
412+ let _guard = ENV_LOCK . lock ( ) ;
413413 let mut environ = * environ ( ) ;
414414 if environ == ptr:: null ( ) {
415- ENV_LOCK . unlock ( ) ;
416415 panic ! ( "os::env() failure getting env string from OS: {}" ,
417416 io:: Error :: last_os_error( ) ) ;
418417 }
@@ -423,12 +422,10 @@ pub fn env() -> Env {
423422 }
424423 environ = environ. offset ( 1 ) ;
425424 }
426- let ret = Env {
425+ return Env {
427426 iter : result. into_iter ( ) ,
428427 _dont_send_or_sync_me : PhantomData ,
429- } ;
430- ENV_LOCK . unlock ( ) ;
431- return ret
428+ }
432429 }
433430
434431 fn parse ( input : & [ u8 ] ) -> Option < ( OsString , OsString ) > {
@@ -452,15 +449,14 @@ pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> {
452449 // always None as well
453450 let k = CString :: new ( k. as_bytes ( ) ) ?;
454451 unsafe {
455- ENV_LOCK . lock ( ) ;
452+ let _guard = ENV_LOCK . lock ( ) ;
456453 let s = libc:: getenv ( k. as_ptr ( ) ) as * const libc:: c_char ;
457454 let ret = if s. is_null ( ) {
458455 None
459456 } else {
460457 Some ( OsStringExt :: from_vec ( CStr :: from_ptr ( s) . to_bytes ( ) . to_vec ( ) ) )
461458 } ;
462- ENV_LOCK . unlock ( ) ;
463- return Ok ( ret)
459+ Ok ( ret)
464460 }
465461}
466462
@@ -469,21 +465,17 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
469465 let v = CString :: new ( v. as_bytes ( ) ) ?;
470466
471467 unsafe {
472- ENV_LOCK . lock ( ) ;
473- let ret = cvt ( libc:: setenv ( k. as_ptr ( ) , v. as_ptr ( ) , 1 ) ) . map ( |_| ( ) ) ;
474- ENV_LOCK . unlock ( ) ;
475- return ret
468+ let _guard = ENV_LOCK . lock ( ) ;
469+ cvt ( libc:: setenv ( k. as_ptr ( ) , v. as_ptr ( ) , 1 ) ) . map ( |_| ( ) )
476470 }
477471}
478472
479473pub fn unsetenv ( n : & OsStr ) -> io:: Result < ( ) > {
480474 let nbuf = CString :: new ( n. as_bytes ( ) ) ?;
481475
482476 unsafe {
483- ENV_LOCK . lock ( ) ;
484- let ret = cvt ( libc:: unsetenv ( nbuf. as_ptr ( ) ) ) . map ( |_| ( ) ) ;
485- ENV_LOCK . unlock ( ) ;
486- return ret
477+ let _guard = ENV_LOCK . lock ( ) ;
478+ cvt ( libc:: unsetenv ( nbuf. as_ptr ( ) ) ) . map ( |_| ( ) )
487479 }
488480}
489481
0 commit comments