From: Karel Zak Date: Wed, 1 Feb 2012 12:37:57 +0000 (+0100) Subject: newgrp: fix possible FILE leak on error X-Git-Tag: v2.21-rc2~33 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1f19513b72aff75180e70efef0efd07712c97c0e;p=thirdparty%2Futil-linux.git newgrp: fix possible FILE leak on error Signed-off-by: Karel Zak --- diff --git a/login-utils/newgrp.c b/login-utils/newgrp.c index d8ae2cf99d..85cba7752a 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)) {