mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
LibC: Stop leaking FILE in getpwuid
and getpwnam
This commit is contained in:
parent
ee5ee0ef86
commit
b2454888e8
Notes:
sideshowbarker
2024-07-17 09:40:51 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/b2454888e8 Pull-request: https://github.com/SerenityOS/serenity/pull/14499
1 changed files with 3 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue