1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-18 04:58:51 +02:00

Check return value of getsockopt().

Checking the return value is not terribly important here, but if setsockopt() fails it is likely that bind() will fail as well. May as well get it over with and this makes Coverity happy.
This commit is contained in:
David Steele 2021-10-25 15:31:39 -04:00
parent 1152f7a7d6
commit 13d4559708
2 changed files with 8 additions and 2 deletions

View File

@ -164,7 +164,10 @@
<release-development-list>
<release-item>
<github-pull-request id="1504"/>
<commit subject="Add TLS server.">
<github-pull-request id="1504"/>
</commit>
<commit subject="Check return value of getsockopt()."/>
<release-item-contributor-list>
<release-item-contributor id="david.steele"/>

View File

@ -176,7 +176,10 @@ sckServerNew(const String *const address, const unsigned int port, const TimeMSe
// Set the address as reusable so we can bind again quickly after a restart or crash
int reuseAddr = 1;
setsockopt(driver->socket, SOL_SOCKET, SO_REUSEADDR, &reuseAddr, sizeof(reuseAddr));
THROW_ON_SYS_ERROR(
setsockopt(driver->socket, SOL_SOCKET, SO_REUSEADDR, &reuseAddr, sizeof(reuseAddr)) == -1, ProtocolError,
"unable to set SO_REUSEADDR");
// Ensure file descriptor is closed
memContextCallbackSet(driver->memContext, sckServerFreeResource, driver);