From: Karel Zak Date: Wed, 24 Jan 2024 08:49:39 +0000 (+0100) Subject: liblastlog2: fix leaks X-Git-Tag: v2.40-rc1~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cf0305dda5f254f1128a9a76651b74c606bce14b;p=thirdparty%2Futil-linux.git liblastlog2: fix leaks * close imported file in ll2_import_lastlog() * free error message in pam_lastlog2.c Signed-off-by: Karel Zak --- diff --git a/liblastlog2/src/lastlog2.c b/liblastlog2/src/lastlog2.c index 827bfe8663..744d41f1aa 100644 --- a/liblastlog2/src/lastlog2.c +++ b/liblastlog2/src/lastlog2.c @@ -533,22 +533,21 @@ ll2_import_lastlog(struct ll2_context *context, const char *lastlog_file, ll_fp = fopen(lastlog_file, "r"); if (ll_fp == NULL) { - if (error) - if (asprintf(error, "Failed to open '%s': %s", + if (error && asprintf(error, "Failed to open '%s': %s", lastlog_file, strerror(errno)) < 0) - return -ENOMEM; + return -ENOMEM; return -1; } - if (fstat (fileno(ll_fp), &statll) != 0) { - if (error) - if (asprintf(error, "Cannot get size of '%s': %s", - lastlog_file, strerror(errno)) < 0) - return -ENOMEM; + if (fstat(fileno(ll_fp), &statll) != 0) { + retval = -1; + if (error && asprintf(error, "Cannot get size of '%s': %s", + lastlog_file, strerror(errno)) < 0) + retval = -ENOMEM; - return -1; + goto done; } setpwent(); @@ -589,6 +588,8 @@ ll2_import_lastlog(struct ll2_context *context, const char *lastlog_file, out_import_lastlog: endpwent(); sqlite3_close(db); +done: + fclose(ll_fp); return retval; } diff --git a/pam_lastlog2/src/pam_lastlog2.c b/pam_lastlog2/src/pam_lastlog2.c index 2802f09b28..e800700bf5 100644 --- a/pam_lastlog2/src/pam_lastlog2.c +++ b/pam_lastlog2/src/pam_lastlog2.c @@ -226,6 +226,7 @@ show_lastlogin (pam_handle_t *pamh, int ctrl, const char *user) { /* DB file not found --> it is OK */ ll2_unref_context(context); + free(error); return PAM_SUCCESS; } if (error) {