mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 03:22:43 +00:00 
			
		
		
		
	LibCore: Do not leak FILE pointer in Group::add_group()
By using a ScopeGuard we make sure that we always close the FILE, also on early returns.
This commit is contained in:
		
							parent
							
								
									6df3fdd83f
								
							
						
					
					
						commit
						1fb8408aa2
					
				
					 1 changed files with 5 additions and 2 deletions
				
			
		|  | @ -5,6 +5,7 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <AK/CharacterTypes.h> | ||||
| #include <AK/ScopeGuard.h> | ||||
| #include <LibCore/Group.h> | ||||
| #include <LibCore/System.h> | ||||
| 
 | ||||
|  | @ -48,11 +49,13 @@ ErrorOr<void> Group::add_group(Group& group) | |||
|     if (!file) | ||||
|         return Error::from_errno(errno); | ||||
| 
 | ||||
|     ScopeGuard file_guard { [&] { | ||||
|         fclose(file); | ||||
|     } }; | ||||
| 
 | ||||
|     if (putgrent(&gr, file) < 0) | ||||
|         return Error::from_errno(errno); | ||||
| 
 | ||||
|     fclose(file); | ||||
| 
 | ||||
|     return {}; | ||||
| } | ||||
| #endif | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Kenneth Myhra
						Kenneth Myhra