From 3af1d7b0ce3a8e3ae565e7cea10cee6fd7cb8109 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 31 Aug 2023 11:31:11 +0200 Subject: [PATCH] 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). --- ChangeLog | 6 ++++++ lib/readutmp.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 9c9c89638c..f34d2a7428 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2023-08-31 Bruno Haible + + 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 readutmp: fix core dump if --enable-systemd diff --git a/lib/readutmp.c b/lib/readutmp.c index e99158677c..ec09feb59b 100644 --- a/lib/readutmp.c +++ b/lib/readutmp.c @@ -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++) -- 2.39.5