summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC
diff options
context:
space:
mode:
authorAndrew Kaster <akaster@serenityos.org>2022-06-14 18:54:49 -0600
committerAndreas Kling <kling@serenityos.org>2022-06-19 09:05:35 +0200
commit6eb9ebec5f2c8dcc937ee048dcede2d4a15c1f8f (patch)
treec371d2881aaba5f06e40c1b6e3452351e1a6862a /Userland/Libraries/LibC
parent455038d6fc809039b9a1a3606f84ed762b08bb8c (diff)
downloadserenity-6eb9ebec5f2c8dcc937ee048dcede2d4a15c1f8f.zip
LibC: Stop leaking FILE* from use of getgrnam and getgrgid
Diffstat (limited to 'Userland/Libraries/LibC')
-rw-r--r--Userland/Libraries/LibC/grp.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/Userland/Libraries/LibC/grp.cpp b/Userland/Libraries/LibC/grp.cpp
index 676be6b1c3..94ad2b2634 100644
--- a/Userland/Libraries/LibC/grp.cpp
+++ b/Userland/Libraries/LibC/grp.cpp
@@ -5,6 +5,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/ScopeGuard.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <errno.h>
@@ -58,6 +59,7 @@ void endgrent()
struct group* getgrgid(gid_t gid)
{
setgrent();
+ ScopeGuard guard = [] { endgrent(); };
while (auto* gr = getgrent()) {
if (gr->gr_gid == gid)
return gr;
@@ -68,6 +70,7 @@ struct group* getgrgid(gid_t gid)
struct group* getgrnam(char const* name)
{
setgrent();
+ ScopeGuard guard = [] { endgrent(); };
while (auto* gr = getgrent()) {
if (!strcmp(gr->gr_name, name))
return gr;