If the canonical hostname was "localhost", the address info was not freed.
Don't bother checking whether ai_canonname is NULL because if there is no canonical name, getaddrinfo must set ai_canonname to the input name.
Fixes: ca5a6d07dc92ba631b178ec175e6b3fd5295e3d6
-- v2: wineboot: Fix a memory leak in create_computer_name_keys.
From: Alex Henrie alexhenrie24@gmail.com
If the canonical hostname was "localhost", the address info was not freed.
Don't bother checking whether ai_canonname is NULL because if there is no canonical name, getaddrinfo must set ai_canonname to the input name.
Fixes: ca5a6d07dc92ba631b178ec175e6b3fd5295e3d6 --- programs/wineboot/wineboot.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/programs/wineboot/wineboot.c b/programs/wineboot/wineboot.c index 8359e5d4c44..ae17fe42325 100644 --- a/programs/wineboot/wineboot.c +++ b/programs/wineboot/wineboot.c @@ -833,15 +833,16 @@ static void create_computer_name_keys(void)
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) + if (getaddrinfo( buffer, NULL, &hints, &res )) + res = NULL; + else if (strcasecmp( res->ai_canonname, "localhost" ) != 0) name = res->ai_canonname; dot = strchr( name, '.' ); if (dot) *dot++ = 0; 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;
On Tue Sep 9 00:25:29 2025 +0000, Elizabeth Figura wrote:
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.
I pushed a new version that splits up the if statement as Jinoh suggested. I hear what you are saying that it's OK for short-lived programs to leak memory. From my perspective, I'd rather free the memory explicitly because wineboot.exe does enough stuff that it wouldn't be obvious that the leak was intentional. But feel free to send an alternative that drops the call to freeaddrinfo if you prefer.