aboutsummaryrefslogtreecommitdiff
path: root/sethostent.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sethostent.cpp')
-rw-r--r--sethostent.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/sethostent.cpp b/sethostent.cpp
index 419ee869..70bb9553 100644
--- a/sethostent.cpp
+++ b/sethostent.cpp
@@ -77,6 +77,8 @@ int _hf_gethtbyname2(const char* name, int af, getnamaddr* info) {
return (rc == NETDB_SUCCESS ? 0 : EAI_NODATA);
}
+ // TODO: Wrap the 'hf' into a RAII class or std::shared_ptr and modify the
+ // sethostent_r()/endhostent_r() to get rid of manually endhostent_r(&hf) everywhere.
FILE* hf = NULL;
sethostent_r(&hf);
if (hf == NULL) {
@@ -88,6 +90,7 @@ int _hf_gethtbyname2(const char* name, int af, getnamaddr* info) {
}
if ((ptr = buf = (char*) malloc(len = info->buflen)) == NULL) {
+ endhostent_r(&hf);
return EAI_MEMORY;
}
@@ -111,6 +114,7 @@ int _hf_gethtbyname2(const char* name, int af, getnamaddr* info) {
if (hp->h_name == nullptr) {
free(buf);
+ endhostent_r(&hf);
return EAI_FAIL;
}
const char* h_name = hp->h_name;
@@ -136,9 +140,9 @@ int _hf_gethtbyname2(const char* name, int af, getnamaddr* info) {
if ((size_t)(ptr - buf) >= info->buflen) goto nospc;
}
- if (num >= MAXADDRS) goto nospc;
if (hp->h_addr_list[0] == nullptr) {
free(buf);
+ endhostent_r(&hf);
return EAI_FAIL;
}
const char* addr = hp->h_addr_list[0];
@@ -193,6 +197,7 @@ int _hf_gethtbyname2(const char* name, int af, getnamaddr* info) {
free(buf);
return 0;
nospc:
+ endhostent_r(&hf);
free(buf);
return EAI_MEMORY;
}