mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 11:18:13 +00:00
LibC: Stop leaking FILE* from use of getgrnam and getgrgid
This commit is contained in:
parent
455038d6fc
commit
6eb9ebec5f
1 changed files with 3 additions and 0 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue