From 6f5515e4613c3f80a049bf24f2dd9366ae3575ea Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Mon, 8 Jun 2015 15:46:27 +0900 Subject: [PATCH 2/2] Additional leak fixes for src/bin stuff The result of getaddrinfo() should be freed with freeaddrinfo. --- src/bin/initdb/initdb.c | 5 ++++- src/bin/pg_upgrade/check.c | 6 ++++++ src/test/regress/pg_regress.c | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index feeff9e..5bda707 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -1359,7 +1359,7 @@ setup_config(void) * have to run on a machine without. */ { - struct addrinfo *gai_result; + struct addrinfo *gai_result = NULL; struct addrinfo hints; int err = 0; @@ -1385,6 +1385,8 @@ setup_config(void) conflines = replace_token(conflines, "host all all ::1", "#host all all ::1"); + if (gai_result) + freeaddrinfo(gai_result); } #else /* !HAVE_IPV6 */ /* If we didn't compile IPV6 support at all, always comment it out */ @@ -2191,6 +2193,7 @@ set_info_version(void) micro = strtol(endptr + 1, &endptr, 10); snprintf(infoversion, sizeof(infoversion), "%02ld.%02ld.%04ld%s", major, minor, micro, letterversion); + pg_free(vstr); } /* diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 5a91871..41d4606 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -337,8 +337,14 @@ equivalent_locale(int category, const char *loca, const char *locb) lenb = charb ? (charb - canonb) : strlen(canonb); if (lena == lenb && pg_strncasecmp(canona, canonb, lena) == 0) + { + pg_free(canona); + pg_free(canonb); return true; + } + pg_free(canona); + pg_free(canonb); return false; } diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c index a267894..6bfb498 100644 --- a/src/test/regress/pg_regress.c +++ b/src/test/regress/pg_regress.c @@ -969,7 +969,7 @@ config_sspi_auth(const char *pgdata) * ::1 (IPv6 loopback) as a numeric host address string. */ { - struct addrinfo *gai_result; + struct addrinfo *gai_result = NULL; struct addrinfo hints; WSADATA wsaData; @@ -984,6 +984,8 @@ config_sspi_auth(const char *pgdata) have_ipv6 = (WSAStartup(MAKEWORD(2, 2), &wsaData) == 0 && getaddrinfo("::1", NULL, &hints, &gai_result) == 0); + if (gai_result) + freeaddrinfo(gai_result); } /* Check a Write outcome and report any error. */ -- 2.4.3