]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
liblastlog2: fix leaks
authorKarel Zak <kzak@redhat.com>
Wed, 24 Jan 2024 08:49:39 +0000 (09:49 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 24 Jan 2024 08:49:39 +0000 (09:49 +0100)
* close imported file in ll2_import_lastlog()

* free error message in pam_lastlog2.c

Signed-off-by: Karel Zak <kzak@redhat.com>
liblastlog2/src/lastlog2.c
pam_lastlog2/src/pam_lastlog2.c

index 827bfe86637a17bd66ee357ba092da36f6323184..744d41f1aaae43bb160b8c3115d4db36a51e5845 100644 (file)
@@ -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;
 }
index 2802f09b283005efa254ae3c852dec8110b92f03..e800700bf5879595c41b7691318409cd13d85422 100644 (file)
@@ -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) {