]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
newgrp: fix possible FILE leak on error
authorKarel Zak <kzak@redhat.com>
Wed, 1 Feb 2012 12:37:57 +0000 (13:37 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 1 Feb 2012 12:37:57 +0000 (13:37 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/newgrp.c

index d8ae2cf99dff07ee4ac695e49ad317287ceb306f..85cba7752a40ec75f276dc53d26920f12ba8bee5 100644 (file)
@@ -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)) {