Fix Coverity warnings regarding r293229

rpcbind/check_bound.c
	Fix CID1347798, a memory leak in mergeaddr.

rpcbind/tests/addrmerge_test.c
	Fix CID1347800 through CID1347803, memory leaks in ATF tests.  They
	are harmless because each ATF test case runs in its own process, but
	they are trivial to fix.  Fix a few other leaks that Coverity didn't
	detect, too.

Coverity CID:	1347798, 1347800, 1347801, 1347802, 1347803
MFC after:	2 weeks
X-MFC-With:	293229
Sponsored by:	Spectra Logic Corp
This commit is contained in:
Alan Somers 2016-01-13 17:33:50 +00:00
parent fafb1ee7bd
commit 0191f57ff1
2 changed files with 28 additions and 5 deletions

View File

@ -184,18 +184,19 @@ mergeaddr(SVCXPRT *xprt, char *netid, char *uaddr, char *saddr)
dg_data = (struct svc_dg_data*)xprt->xp_p2;
if (dg_data != NULL && dg_data->su_srcaddr.buf != NULL) {
c_uaddr = taddr2uaddr(fdl->nconf, &dg_data->su_srcaddr);
allocated_uaddr = c_uaddr;
}
else if (saddr != NULL) {
c_uaddr = saddr;
} else {
c_uaddr = taddr2uaddr(fdl->nconf, svc_getrpccaller(xprt));
if (c_uaddr == NULL) {
syslog(LOG_ERR, "taddr2uaddr failed for %s",
fdl->nconf->nc_netid);
return (NULL);
}
allocated_uaddr = c_uaddr;
}
if (c_uaddr == NULL) {
syslog(LOG_ERR, "taddr2uaddr failed for %s",
fdl->nconf->nc_netid);
return (NULL);
}
#ifdef ND_DEBUG
if (debugging) {

View File

@ -435,6 +435,7 @@ ATF_TC_BODY(addrmerge_localhost_only, tc)
/* We must return localhost if there is nothing better */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("127.0.0.1.3.46", maddr);
free(maddr);
}
ATF_TC_WITHOUT_HEAD(addrmerge_singlehomed);
@ -450,6 +451,7 @@ ATF_TC_BODY(addrmerge_singlehomed, tc)
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("192.0.2.2.3.46", maddr);
free(maddr);
}
ATF_TC_WITHOUT_HEAD(addrmerge_one_addr_on_each_subnet);
@ -466,6 +468,7 @@ ATF_TC_BODY(addrmerge_one_addr_on_each_subnet, tc)
/* We must return the address on the caller's subnet */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("192.0.2.2.3.46", maddr);
free(maddr);
}
@ -488,6 +491,7 @@ ATF_TC_BODY(addrmerge_one_addr_on_each_subnet_rev, tc)
/* We must return the address on the caller's subnet */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("192.0.2.2.3.46", maddr);
free(maddr);
}
ATF_TC_WITHOUT_HEAD(addrmerge_point2point);
@ -505,6 +509,7 @@ ATF_TC_BODY(addrmerge_point2point, tc)
/* addrmerge should disprefer P2P interfaces */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("192.0.2.130.3.46", maddr);
free(maddr);
}
/* Like addrerge_point2point, but getifaddrs returns a different order */
@ -523,6 +528,7 @@ ATF_TC_BODY(addrmerge_point2point_rev, tc)
/* addrmerge should disprefer P2P interfaces */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("192.0.2.130.3.46", maddr);
free(maddr);
}
/*
@ -544,6 +550,7 @@ ATF_TC_BODY(addrmerge_bindip, tc)
/* We must return the address to which we are bound */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("192.0.2.3.3.46", maddr);
free(maddr);
}
/* Like addrmerge_bindip, but getifaddrs returns a different order */
@ -562,6 +569,7 @@ ATF_TC_BODY(addrmerge_bindip_rev, tc)
/* We must return the address to which we are bound */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("192.0.2.3.3.46", maddr);
free(maddr);
}
/*
@ -582,6 +590,7 @@ ATF_TC_BODY(addrmerge_recvdstaddr, tc)
/* We must return the address on which the request was received */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("192.0.2.2.3.46", maddr);
free(maddr);
}
ATF_TC_WITHOUT_HEAD(addrmerge_recvdstaddr_rev);
@ -598,6 +607,7 @@ ATF_TC_BODY(addrmerge_recvdstaddr_rev, tc)
/* We must return the address on which the request was received */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("192.0.2.2.3.46", maddr);
free(maddr);
}
#ifdef INET6
@ -614,6 +624,7 @@ ATF_TC_BODY(addrmerge_localhost_only6, tc)
/* We must return localhost if there is nothing better */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("::1.3.46", maddr);
free(maddr);
}
ATF_TC_WITHOUT_HEAD(addrmerge_singlehomed6);
@ -629,6 +640,7 @@ ATF_TC_BODY(addrmerge_singlehomed6, tc)
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("2001:db8::2.3.46", maddr);
free(maddr);
}
ATF_TC_WITHOUT_HEAD(addrmerge_one_addr_on_each_subnet6);
@ -645,6 +657,7 @@ ATF_TC_BODY(addrmerge_one_addr_on_each_subnet6, tc)
/* We must return the address on the caller's subnet */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("2001:db8::2.3.46", maddr);
free(maddr);
}
@ -667,6 +680,7 @@ ATF_TC_BODY(addrmerge_one_addr_on_each_subnet6_rev, tc)
/* We must return the address on the caller's subnet */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("2001:db8::2.3.46", maddr);
free(maddr);
}
ATF_TC_WITHOUT_HEAD(addrmerge_point2point6);
@ -684,6 +698,7 @@ ATF_TC_BODY(addrmerge_point2point6, tc)
/* addrmerge should disprefer P2P interfaces */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("2001:db8:1::2.3.46", maddr);
free(maddr);
}
/* Like addrerge_point2point, but getifaddrs returns a different order */
@ -702,6 +717,7 @@ ATF_TC_BODY(addrmerge_point2point6_rev, tc)
/* addrmerge should disprefer P2P interfaces */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("2001:db8:1::2.3.46", maddr);
free(maddr);
}
ATF_TC_WITHOUT_HEAD(addrmerge_bindip6);
@ -719,6 +735,7 @@ ATF_TC_BODY(addrmerge_bindip6, tc)
/* We must return the address to which we are bound */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("2001:db8::3.3.46", maddr);
free(maddr);
}
/* Like addrerge_bindip, but getifaddrs returns a different order */
@ -737,6 +754,7 @@ ATF_TC_BODY(addrmerge_bindip6_rev, tc)
/* We must return the address to which we are bound */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("2001:db8::3.3.46", maddr);
free(maddr);
}
/*
@ -761,6 +779,7 @@ ATF_TC_BODY(addrmerge_ipv6_linklocal, tc)
/* We must return the address to which we are bound */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("fe80::2.3.46", maddr);
free(maddr);
}
ATF_TC_WITHOUT_HEAD(addrmerge_ipv6_linklocal_rev);
@ -781,6 +800,7 @@ ATF_TC_BODY(addrmerge_ipv6_linklocal_rev, tc)
/* We must return the address to which we are bound */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("fe80::2.3.46", maddr);
free(maddr);
}
ATF_TC_WITHOUT_HEAD(addrmerge_recvdstaddr6);
@ -797,6 +817,7 @@ ATF_TC_BODY(addrmerge_recvdstaddr6, tc)
/* We must return the address on which the request was received */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("2001:db8::2.3.46", maddr);
free(maddr);
}
ATF_TC_WITHOUT_HEAD(addrmerge_recvdstaddr6_rev);
@ -813,6 +834,7 @@ ATF_TC_BODY(addrmerge_recvdstaddr6_rev, tc)
/* We must return the address on which the request was received */
ATF_REQUIRE(maddr != NULL);
ATF_CHECK_STREQ("2001:db8::2.3.46", maddr);
free(maddr);
}
#endif /* INET6 */