[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging] tools/console/daemon: fix log_dir memory leak in xenconsoled



commit 1771ba84501cb62a9e9f9fc60db9bbe44c6d1c57
Author:     Andrew Mbugua <andrewprecious388@xxxxxxxxx>
AuthorDate: Fri Aug 14 00:27:23 2026 +0300
Commit:     Anthony PERARD <anthony.perard@xxxxxxxxxx>
CommitDate: Mon Oct 12 17:31:39 2026 +0200

    tools/console/daemon: fix log_dir memory leak in xenconsoled
    
    Valgrind reports that 21 bytes are "still reachable" from the (XEN_LOG_DIR 
"/console") allocation:
    
    HEAP SUMMARY:
        in use at exit: 21 bytes in 1 blocks
        total heap usage: 9 allocs, 8 frees, 4,799 bytes allocated
    
    Since the dynamic memory allocation for the default log directory path 
happens before the process
    forks into the background, the parent and intermediate processes exit 
during daemonize()
    with the memory still reachable.
    
    Move the strdup() allocation down below the daemonize() block. This ensures 
only the final
    background daemon allocates the default path, matching the lifetime of the 
free(log_dir)
    cleanup loop at the exit of main().
    
    With this change, Valgrind reports a clean heap summary
    
    HEAP SUMMARY:
        in use at exit: 0 bytes in 0 blocks
        total heap usage: 8 allocs, 8 frees, 4,778 bytes allocated
    
    Signed-off-by: Andrew Mbugua <andrewprecious388@xxxxxxxxx>
    Reviewed-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
---
 tools/console/daemon/main.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/console/daemon/main.c b/tools/console/daemon/main.c
index aac7233a48..798077ac2f 100644
--- a/tools/console/daemon/main.c
+++ b/tools/console/daemon/main.c
@@ -181,10 +181,6 @@ int main(int argc, char **argv)
                }
        }
 
-       if (!log_dir) {
-               log_dir = strdup(XEN_LOG_DIR "/console");
-       }
-
        if (geteuid() != 0) {
                fprintf(stderr, "%s requires root to run.\n", argv[0]);
                exit(EPERM);
@@ -201,6 +197,10 @@ int main(int argc, char **argv)
                daemonize(pidfile ? pidfile : XEN_RUN_DIR "/xenconsoled.pid");
        }
 
+       if (!log_dir) {
+               log_dir = strdup(XEN_LOG_DIR "/console");
+       }
+
        if (!xen_setup())
                exit(1);
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.