summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2013-05-12 13:15:11 +0200
committerTobias Klauser <tklauser@distanz.ch>2013-05-12 13:18:23 +0200
commite12a08652f7d2b92e75d8dd7b8528d1d0e69b2a8 (patch)
treead446f3eb4e40e4aeecad8b919537b4c3827034d
parent10a80a61d67516c0ba4c13a7c07e9ebfa6fab9c5 (diff)
geoip: Don't leak file/socket descriptor in error case
In certain error cases, the file/socket descriptors are not closed in geoip_get_database(). This was discovered by the coverity scanner. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--geoip.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/geoip.c b/geoip.c
index c4c6cf8..b2121e7 100644
--- a/geoip.c
+++ b/geoip.c
@@ -177,8 +177,10 @@ again:
files[which].remote, host);
ret = write(sock, raw, strlen(raw));
- if (ret <= 0)
+ if (ret <= 0) {
+ close(sock);
return -EIO;
+ }
shutdown(sock, SHUT_WR);
@@ -187,8 +189,11 @@ again:
memset(raw, 0, sizeof(raw));
ret = read(sock, raw, sizeof(raw));
- if (ret <= 0)
+ if (ret <= 0) {
+ close(fd);
+ close(sock);
return -EIO;
+ }
raw[sizeof(raw) - 1] = 0;
@@ -210,10 +215,11 @@ again:
}
if (!found || ptr >= raw + ret || len < 0 || rtotlen == 0 || good == 0) {
+ close(fd);
+ close(sock);
+
if (retry == 0) {
retry = 1;
- close(fd);
- close(sock);
goto again;
}