]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/utmp.c: get_session_host(): Fix memory leak
authorAlejandro Colomar <alx@kernel.org>
Mon, 14 Jul 2025 12:08:52 +0000 (14:08 +0200)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Mon, 11 Aug 2025 08:18:19 +0000 (10:18 +0200)
Fixes: f40bdfa66a3a (2023-08-02; "libmisc: implement `get_session_host()`")
Closes: <https://github.com/shadow-maint/shadow/issues/1291>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/utmp.c

index 90ac9d18c962204a6064e42f45e1c30a2962f6b2..4acf95a7f8c23dce9f9265e813322502e6cc5c34 100644 (file)
@@ -208,7 +208,6 @@ get_session_host(char **out, pid_t main_pid)
 #if defined(HAVE_STRUCT_UTMPX_UT_HOST)
        if ((ut != NULL) && (ut->ut_host[0] != '\0')) {
                *out = XSTRNDUP(ut->ut_host);
-               free (ut);
        } else {
                *out = NULL;
                ret = -2;
@@ -218,6 +217,8 @@ get_session_host(char **out, pid_t main_pid)
        ret = -2;
 #endif
 
+       free(ut);
+
        return ret;
 }