summaryrefslogtreecommitdiffstats
path: root/login-utils/newgrp.c
diff options
context:
space:
mode:
authorKarel Zak2012-02-01 13:37:57 +0100
committerKarel Zak2012-02-01 13:37:57 +0100
commit1f19513b72aff75180e70efef0efd07712c97c0e (patch)
tree90ad92ec05c17cb96f9aab63e46cbe4722c7a3d7 /login-utils/newgrp.c
parentlib/loopdev: fix possible dir leak on error (diff)
downloadkernel-qcow2-util-linux-1f19513b72aff75180e70efef0efd07712c97c0e.tar.gz
kernel-qcow2-util-linux-1f19513b72aff75180e70efef0efd07712c97c0e.tar.xz
kernel-qcow2-util-linux-1f19513b72aff75180e70efef0efd07712c97c0e.zip
newgrp: fix possible FILE leak on error
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils/newgrp.c')
-rw-r--r--login-utils/newgrp.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/login-utils/newgrp.c b/login-utils/newgrp.c
index d8ae2cf99..85cba7752 100644
--- a/login-utils/newgrp.c
+++ b/login-utils/newgrp.c
@@ -28,9 +28,13 @@ static char *get_gshadow_pwd(char *groupname)
{
char buf[BUFSIZ];
char *pwd = NULL;
- FILE *f = fopen(_PATH_GSHADOW, "r");
+ FILE *f;
- if (groupname == NULL || *groupname == '\0' || f == NULL)
+ if (groupname == NULL || *groupname == '\0')
+ return NULL;
+
+ f = fopen(_PATH_GSHADOW, "r");
+ if (!f)
return NULL;
while (fgets(buf, sizeof buf, f)) {