mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-10 11:36:22 +00: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: 6eb9ebec5f
Pull-request: https://github.com/SerenityOS/serenity/pull/14283
Reviewed-by: https://github.com/linusg
Reviewed-by: https://github.com/timschumi
1 changed files with 3 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/ScopeGuard.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -58,6 +59,7 @@ void endgrent()
|
||||||
struct group* getgrgid(gid_t gid)
|
struct group* getgrgid(gid_t gid)
|
||||||
{
|
{
|
||||||
setgrent();
|
setgrent();
|
||||||
|
ScopeGuard guard = [] { endgrent(); };
|
||||||
while (auto* gr = getgrent()) {
|
while (auto* gr = getgrent()) {
|
||||||
if (gr->gr_gid == gid)
|
if (gr->gr_gid == gid)
|
||||||
return gr;
|
return gr;
|
||||||
|
@ -68,6 +70,7 @@ struct group* getgrgid(gid_t gid)
|
||||||
struct group* getgrnam(char const* name)
|
struct group* getgrnam(char const* name)
|
||||||
{
|
{
|
||||||
setgrent();
|
setgrent();
|
||||||
|
ScopeGuard guard = [] { endgrent(); };
|
||||||
while (auto* gr = getgrent()) {
|
while (auto* gr = getgrent()) {
|
||||||
if (!strcmp(gr->gr_name, name))
|
if (!strcmp(gr->gr_name, name))
|
||||||
return gr;
|
return gr;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue