diff options
| author | George Zacharia <george.zcharia@gmail.com> | 2024-07-04 12:11:39 +0530 |
|---|---|---|
| committer | George Zacharia <george.zcharia@gmail.com> | 2024-07-04 12:11:39 +0530 |
| commit | 5d39b58c917af54cc5364cb54a91a2fbb35c0684 (patch) | |
| tree | 785644acbdb68cb56f5935928fd3ccd8cc5602cc /sethostent.cpp | |
| parent | 31fe821335034ba4fb29953fe77395c804e51a33 (diff) | |
| parent | fe72ac15ad7f0428e662415458cc51e03746e33e (diff) | |
Merge tag 'android-14.0.0_r50' of https://android.googlesource.com/platform/packages/modules/DnsResolver into u14.0HEADu14.0
Android 14.0.0 Release 50 (AP2A.240605.024)
Diffstat (limited to 'sethostent.cpp')
| -rw-r--r-- | sethostent.cpp | 7 |
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; } |
