[PATCH 0/1] MR8918: wineboot: Fix a memory leak in create_computer_name_keys.
If the canonical hostname was "localhost", the address info was not freed. Also, since we're touching the same line that defines the address info hints, make the hints `static const` so that the compiler knows it's safe to put them in read-only memory if it wants. Fixes: ca5a6d07dc92ba631b178ec175e6b3fd5295e3d6 -- https://gitlab.winehq.org/wine/wine/-/merge_requests/8918
From: Alex Henrie <alexhenrie24(a)gmail.com> If the canonical hostname was "localhost", the address info was not freed. Also, since we're touching the same line that defines the address info hints, make the hints `static const` so that the compiler knows it's safe to put them in read-only memory if it wants. Fixes: ca5a6d07dc92ba631b178ec175e6b3fd5295e3d6 --- programs/wineboot/wineboot.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/programs/wineboot/wineboot.c b/programs/wineboot/wineboot.c index 8359e5d4c44..94ef024e32a 100644 --- a/programs/wineboot/wineboot.c +++ b/programs/wineboot/wineboot.c @@ -827,12 +827,12 @@ static void create_dynamic_registry_keys(void) /* create the ComputerName registry keys */ static void create_computer_name_keys(void) { - struct addrinfo hints = {0}, *res; + static const struct addrinfo hints = { .ai_flags = AI_CANONNAME }; + struct addrinfo *res = NULL; char *dot, buffer[256], *name = buffer; HKEY key, subkey; if (gethostname( buffer, sizeof(buffer) )) return; - hints.ai_flags = AI_CANONNAME; if (!getaddrinfo( buffer, NULL, &hints, &res ) && res->ai_canonname && strcasecmp(res->ai_canonname, "localhost") != 0) name = res->ai_canonname; @@ -841,7 +841,7 @@ static void create_computer_name_keys(void) else dot = name + strlen(name); SetComputerNameExA( ComputerNamePhysicalDnsDomain, dot ); SetComputerNameExA( ComputerNamePhysicalDnsHostname, name ); - if (name != buffer) freeaddrinfo( res ); + if (res) freeaddrinfo( res ); if (RegOpenKeyW( HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\ComputerName", &key )) return; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/8918
Jinoh Kang (@iamahuman) commented about programs/wineboot/wineboot.c:
/* create the ComputerName registry keys */ static void create_computer_name_keys(void) { - struct addrinfo hints = {0}, *res; + static const struct addrinfo hints = { .ai_flags = AI_CANONNAME }; + struct addrinfo *res = NULL; char *dot, buffer[256], *name = buffer; HKEY key, subkey;
if (gethostname( buffer, sizeof(buffer) )) return; - hints.ai_flags = AI_CANONNAME; if (!getaddrinfo( buffer, NULL, &hints, &res ) && res->ai_canonname && strcasecmp(res->ai_canonname, "localhost") != 0) I think we should avoid assuming the function leaves the out variable untouched on failure. Also, let's take this opportunity to split the condition:
```suggestion:-0+0 if (getaddrinfo( buffer, NULL, &hints, &res )) res = NULL; else if (strcasecmp(res->ai_canonname, "localhost") != 0) ``` (I removed the NULL check for ai\_canonname, seems it's set to eqal nodename rather than set to NULL.) -- https://gitlab.winehq.org/wine/wine/-/merge_requests/8918#note_115260
Jinoh Kang (@iamahuman) commented about programs/wineboot/wineboot.c:
/* create the ComputerName registry keys */ static void create_computer_name_keys(void) { - struct addrinfo hints = {0}, *res; + static const struct addrinfo hints = { .ai_flags = AI_CANONNAME }; + struct addrinfo *res = NULL;
struct addrinfo *res;
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/8918#note_115261
Looks good otherwise. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/8918#note_115262
Probably would be better just to remove the freeaddrinfo()? -- https://gitlab.winehq.org/wine/wine/-/merge_requests/8918#note_115344
On Mon Sep 8 23:29:04 2025 +0000, Elizabeth Figura wrote:
Probably would be better just to remove the freeaddrinfo()? That would add noise to Valgrind and leak detectors output, right? I think those tools are pretty useful otherwise.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/8918#note_115384
On Mon Sep 8 23:29:04 2025 +0000, Jinoh Kang wrote:
That would add noise to Valgrind and leak detectors output, right? I think those tools are pretty useful otherwise. The consistent position is that we don't care about cleaning up memory in short-lived programs, and as a corollary that being able to use them for leak detection is not worthwhile.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/8918#note_115385
participants (4)
-
Alex Henrie -
Alex Henrie (@alexhenrie) -
Elizabeth Figura (@zfigura) -
Jinoh Kang (@iamahuman)