diff options
author | Tim Schumacher <timschumi@gmx.de> | 2022-07-05 23:48:45 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-07-06 10:34:20 +0200 |
commit | b2454888e8fa44775456536a2a71827763cba503 (patch) | |
tree | f32b7bd11c493739acdab6971326170024849814 | |
parent | ee5ee0ef8626264d1ce95c4d8dac48acf10c55f6 (diff) | |
download | serenity-b2454888e8fa44775456536a2a71827763cba503.zip |
LibC: Stop leaking FILE in `getpwuid` and `getpwnam`
-rw-r--r-- | Userland/Libraries/LibC/pwd.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/Userland/Libraries/LibC/pwd.cpp b/Userland/Libraries/LibC/pwd.cpp index b13e4b3db7..3d9ffcb156 100644 --- a/Userland/Libraries/LibC/pwd.cpp +++ b/Userland/Libraries/LibC/pwd.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <AK/ScopeGuard.h> #include <AK/String.h> #include <AK/TemporaryChange.h> #include <AK/Vector.h> @@ -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; |