]> Savannah Git Hosting - gnulib.git/commitdiff
readutmp: Fix memory leak introduced by last commit.
authorBruno Haible <bruno@clisp.org>
Thu, 31 Aug 2023 09:31:11 +0000 (11:31 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 31 Aug 2023 09:31:11 +0000 (11:31 +0200)
* lib/readutmp.c (read_utmp_from_systemd): If num_sessions == 0 and
sessions != NULL, do call free (sessions).

ChangeLog
lib/readutmp.c

index 9c9c89638c0a75aa0c743168d44a132c8adf264f..f34d2a74288ae3d0733226ac19cfd44d3d223086 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-08-31  Bruno Haible  <bruno@clisp.org>
+
+       readutmp: Fix memory leak introduced by last commit.
+       * lib/readutmp.c (read_utmp_from_systemd): If num_sessions == 0 and
+       sessions != NULL, do call free (sessions).
+
 2023-08-30  Paul Eggert  <eggert@cs.ucla.edu>
 
        readutmp: fix core dump if --enable-systemd
index e99158677c88e3044fee580aafcf744cba939a61..ec09feb59b4dd01d26d7b364432648a7475f9528 100644 (file)
@@ -795,7 +795,7 @@ read_utmp_from_systemd (idx_t *n_entries, STRUCT_UTMP **utmp_buf, int options)
     {
       char **sessions;
       int num_sessions = sd_get_sessions (&sessions);
-      if (num_sessions > 0)
+      if (num_sessions >= 0 && sessions != NULL)
         {
           char **session_ptr;
           for (session_ptr = sessions; *session_ptr != NULL; session_ptr++)