summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2022-07-05 23:48:45 +0200
committerLinus Groh <mail@linusgroh.de>2022-07-06 10:34:20 +0200
commitb2454888e8fa44775456536a2a71827763cba503 (patch)
treef32b7bd11c493739acdab6971326170024849814
parentee5ee0ef8626264d1ce95c4d8dac48acf10c55f6 (diff)
downloadserenity-b2454888e8fa44775456536a2a71827763cba503.zip
LibC: Stop leaking FILE in `getpwuid` and `getpwnam`
-rw-r--r--Userland/Libraries/LibC/pwd.cpp3
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;