Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e44735c

Browse files
committed
Fix minor memory leak in ident_inet().
We'd leak the ident_serv data structure if the second pg_getaddrinfo_all (the one for the local address) failed. This is not of great consequence because a failure return here just leads directly to backend exit(), but if this function is going to try to clean up after itself at all, it should not have such holes in the logic. Try to fix it in a future-proof way by having all the failure exits go through the same cleanup path, rather than "optimizing" some of them. Per Coverity. Back-patch to 9.2, which is as far back as this patch applies cleanly.
1 parent ee8d377 commit e44735c

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/backend/libpq/auth.c

+11-10
Original file line numberDiff line numberDiff line change
@@ -1403,8 +1403,7 @@ ident_inet(hbaPort *port)
14031403
const SockAddr remote_addr = port->raddr;
14041404
const SockAddr local_addr = port->laddr;
14051405
char ident_user[IDENT_USERNAME_MAX + 1];
1406-
pgsocket sock_fd; /* File descriptor for socket on which we talk
1407-
* to Ident */
1406+
pgsocket sock_fd = PGINVALID_SOCKET; /* for talking to Ident server */
14081407
int rc; /* Return code from a locally called function */
14091408
bool ident_return;
14101409
char remote_addr_s[NI_MAXHOST];
@@ -1443,9 +1442,9 @@ ident_inet(hbaPort *port)
14431442
rc = pg_getaddrinfo_all(remote_addr_s, ident_port, &hints, &ident_serv);
14441443
if (rc || !ident_serv)
14451444
{
1446-
if (ident_serv)
1447-
pg_freeaddrinfo_all(hints.ai_family, ident_serv);
1448-
return STATUS_ERROR; /* we don't expect this to happen */
1445+
/* we don't expect this to happen */
1446+
ident_return = false;
1447+
goto ident_inet_done;
14491448
}
14501449

14511450
hints.ai_flags = AI_NUMERICHOST;
@@ -1459,9 +1458,9 @@ ident_inet(hbaPort *port)
14591458
rc = pg_getaddrinfo_all(local_addr_s, NULL, &hints, &la);
14601459
if (rc || !la)
14611460
{
1462-
if (la)
1463-
pg_freeaddrinfo_all(hints.ai_family, la);
1464-
return STATUS_ERROR; /* we don't expect this to happen */
1461+
/* we don't expect this to happen */
1462+
ident_return = false;
1463+
goto ident_inet_done;
14651464
}
14661465

14671466
sock_fd = socket(ident_serv->ai_family, ident_serv->ai_socktype,
@@ -1548,8 +1547,10 @@ ident_inet(hbaPort *port)
15481547
ident_inet_done:
15491548
if (sock_fd != PGINVALID_SOCKET)
15501549
closesocket(sock_fd);
1551-
pg_freeaddrinfo_all(remote_addr.addr.ss_family, ident_serv);
1552-
pg_freeaddrinfo_all(local_addr.addr.ss_family, la);
1550+
if (ident_serv)
1551+
pg_freeaddrinfo_all(remote_addr.addr.ss_family, ident_serv);
1552+
if (la)
1553+
pg_freeaddrinfo_all(local_addr.addr.ss_family, la);
15531554

15541555
if (ident_return)
15551556
/* Success! Check the usermap */

0 commit comments

Comments
 (0)