mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
LibC: Stop leaking FILE* from use of getgrnam and getgrgid
This commit is contained in:
parent
455038d6fc
commit
6eb9ebec5f
Notes:
sideshowbarker
2024-07-18 04:38:32 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/6eb9ebec5f Pull-request: https://github.com/SerenityOS/serenity/pull/14283 Reviewed-by: https://github.com/linusg Reviewed-by: https://github.com/timschumi
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user