diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2013-05-12 13:15:11 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2013-05-12 13:18:23 +0200 |
commit | e12a08652f7d2b92e75d8dd7b8528d1d0e69b2a8 (patch) | |
tree | ad446f3eb4e40e4aeecad8b919537b4c3827034d /geoip.c | |
parent | 10a80a61d67516c0ba4c13a7c07e9ebfa6fab9c5 (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>
Diffstat (limited to 'geoip.c')
-rw-r--r-- | geoip.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -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; } |