|
@@ -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
|