[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [XEN PATCH] tools/console/daemon: fix log_dir memory leak in xenconsoled
- To: Jan Beulich <jbeulich@xxxxxxxx>
- From: Andrew Precious <andrewprecious388@xxxxxxxxx>
- Date: Fri, 14 Aug 2026 10:59:22 +0300
- Arc-authentication-results: i=1; mx.google.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=fRktlHtqQOXAxFnJpAxi5xc9vkIb0dW+AHLsSX4rpLU=; fh=UpFTLnCwSi0lAZgmDcfXF/u4JodY0u9pjARRJLeoR/A=; b=VAk9zbbEFiTUiTZLzMVPXYeh19OVoMK9ZmsU8ttZF49ySQx0sbz1HS/rtQL/N00tzq lkLq2Mnn+eR+IzNZv9g9K22J9wrFtRHKzPkXkEqx1jbjoYIEn2FLsWyftphL/g0QFdOT ToUT6K3k/zSKVnhdjzdkZJAy+1FVcWrFzvDt0an7wwcajxW7xmAGvsVAg8/0s4niEooO k+W0eUXg8Z+asLUfg+BSN/fHftFB01SA1R2jzde3gMgw7ZvTF02iBeuaSAHp/KqNNCBC 3NZPPbtpkbTvWA7UT8wCrXJa0zGv5JpwKHZTsvyi9FlMfqV1Tc8wSG+cI4YQKNcaKa/f wmLA==; darn=lists.xenproject.org
- Arc-seal: i=1; a=rsa-sha256; t=1786694373; cv=none; d=google.com; s=arc-20260327; b=C0cdHd/swJJP1NfdKBcDZkibSwG6xPTitxCmXdx+gdXrWR8s1IwY5K2M0zS8tOKVaV 4ArttC6DFVZgs8DH0N8AXcujV9/t6Mq9zHMBeAJ8V0xpqBbHlrmby9rvakiXW+e6UQS9 b2AyAV1KcigZqPH3BOFDkztv6RHQkKxs98wo/DQKfFkSmxaxbPv4eCUBfwJYJUxaXKkz akwjpJ1GTA+XNP0gcYVZxrP4c/AVHUyzZnNgRydqOLERN55E6BOegP+KST3QOdSJJjqC V9uW51GLaEaoVI8cRLPcKYeOW51Kd8SxA+8Hd577wFH/ulHFxCTkNj1yqCcEHmhI8Xh3 YcYQ==
- Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References:MIME-Version"
- Cc: anthony.perard@xxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx
- Delivery-date: Fri, 14 Aug 2026 07:59:42 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
Noted,it's my 1st first time contributing.
Should I generate a version 2 patch for this?
On 13.08.2026 23:27, Andrew Mbugua wrote:
> 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>
Looks all plausible (albeit a little unnecessary, as memory is freed at
program exit anyway), except that ...
> --- 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");
> + }
... can you please not screw up indentation? All you want is to move the
code, without converting tabs to blanks.
Jan
|