From e12a08652f7d2b92e75d8dd7b8528d1d0e69b2a8 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 12 May 2013 13:15:11 +0200 Subject: 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 --- geoip.c | 14 ++++++++++---- 1 file 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; } -- cgit v1.2.3-54-g00ecf