From b2454888e8fa44775456536a2a71827763cba503 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Tue, 5 Jul 2022 23:48:45 +0200 Subject: [PATCH] LibC: Stop leaking FILE in `getpwuid` and `getpwnam` --- Userland/Libraries/LibC/pwd.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Userland/Libraries/LibC/pwd.cpp b/Userland/Libraries/LibC/pwd.cpp index b13e4b3db7f58e..3d9ffcb1567ecc 100644 --- a/Userland/Libraries/LibC/pwd.cpp +++ b/Userland/Libraries/LibC/pwd.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -51,6 +52,7 @@ void endpwent() struct passwd* getpwuid(uid_t uid) { setpwent(); + ScopeGuard guard = [] { endpwent(); }; while (auto* pw = getpwent()) { if (pw->pw_uid == uid) return pw; @@ -61,6 +63,7 @@ struct passwd* getpwuid(uid_t uid) struct passwd* getpwnam(char const* name) { setpwent(); + ScopeGuard guard = [] { endpwent(); }; while (auto* pw = getpwent()) { if (!strcmp(pw->pw_name, name)) return pw;