Index: native_client_sdk/src/libraries/nacl_io/host_resolver.cc |
diff --git a/native_client_sdk/src/libraries/nacl_io/host_resolver.cc b/native_client_sdk/src/libraries/nacl_io/host_resolver.cc |
index beae7261b50ff531bad9224f2326bbf183607d1a..a883a2ad061439ee59caf6540a2f8ac7d7b20ae9 100644 |
--- a/native_client_sdk/src/libraries/nacl_io/host_resolver.cc |
+++ b/native_client_sdk/src/libraries/nacl_io/host_resolver.cc |
@@ -34,6 +34,10 @@ struct hostent* HostResolver::gethostbyname(const char* name) { |
HostResolverInterface* resolver_interface = |
ppapi_->GetHostResolverInterface(); |
+ |
+ if (NULL == resolver_interface) |
+ return NULL; |
+ |
ScopedResource resolver(ppapi_, |
resolver_interface->Create(ppapi_->GetInstance())); |
@@ -88,6 +92,8 @@ struct hostent* HostResolver::gethostbyname(const char* name) { |
memcpy(hostent_.h_name, name_ptr, len); |
hostent_.h_name[len] = '\0'; |
+ ppapi_->GetVarInterface()->Release(name_var); |
+ |
// Aliases aren't supported at the moment, so we just make an empty list. |
hostent_.h_aliases = static_cast<char**>(malloc(sizeof(char*))); |
if (NULL == hostent_.h_aliases) |
@@ -97,8 +103,10 @@ struct hostent* HostResolver::gethostbyname(const char* name) { |
NetAddressInterface* netaddr_interface = ppapi_->GetNetAddressInterface(); |
PP_Resource addr = |
resolver_interface->GetNetAddress(resolver.pp_resource(), 0); |
- if (!PP_ToBool(netaddr_interface->IsNetAddress(addr))) |
+ if (!PP_ToBool(netaddr_interface->IsNetAddress(addr))) { |
+ ppapi_->ReleaseResource(addr); |
return NULL; |
+ } |
switch (netaddr_interface->GetFamily(addr)) { |
case PP_NETADDRESS_FAMILY_IPV4: |
@@ -110,9 +118,12 @@ struct hostent* HostResolver::gethostbyname(const char* name) { |
hostent_.h_length = 16; |
break; |
default: |
+ ppapi_->ReleaseResource(addr); |
return NULL; |
} |
+ ppapi_->ReleaseResource(addr); |
+ |
const uint32_t num_addresses = |
resolver_interface->GetNetAddressCount(resolver.pp_resource()); |
if (0 == num_addresses) |
@@ -125,26 +136,36 @@ struct hostent* HostResolver::gethostbyname(const char* name) { |
for (uint32_t i = 0; i < num_addresses; i++) { |
PP_Resource addr = |
resolver_interface->GetNetAddress(resolver.pp_resource(), i); |
- if (!PP_ToBool(netaddr_interface->IsNetAddress(addr))) |
+ if (!PP_ToBool(netaddr_interface->IsNetAddress(addr))) { |
+ ppapi_->ReleaseResource(addr); |
binji
2014/01/28 18:13:22
You can use a ScopedResource (see pepper_interface
Sam Clegg
2014/01/28 19:55:22
Done.
|
return NULL; |
+ } |
if (AF_INET == hostent_.h_addrtype) { |
struct PP_NetAddress_IPv4 addr_struct; |
if (!netaddr_interface->DescribeAsIPv4Address(addr, &addr_struct)) { |
+ ppapi_->ReleaseResource(addr); |
return NULL; |
} |
hostent_.h_addr_list[i] = static_cast<char*>(malloc(hostent_.h_length)); |
- if (NULL == hostent_.h_addr_list[i]) |
+ if (NULL == hostent_.h_addr_list[i]) { |
+ ppapi_->ReleaseResource(addr); |
return NULL; |
+ } |
memcpy(hostent_.h_addr_list[i], addr_struct.addr, hostent_.h_length); |
} else { // IPv6 |
struct PP_NetAddress_IPv6 addr_struct; |
- if (!netaddr_interface->DescribeAsIPv6Address(addr, &addr_struct)) |
+ if (!netaddr_interface->DescribeAsIPv6Address(addr, &addr_struct)) { |
+ ppapi_->ReleaseResource(addr); |
return NULL; |
+ } |
hostent_.h_addr_list[i] = static_cast<char*>(malloc(hostent_.h_length)); |
- if (NULL == hostent_.h_addr_list[i]) |
+ if (NULL == hostent_.h_addr_list[i]) { |
+ ppapi_->ReleaseResource(addr); |
return NULL; |
+ } |
memcpy(hostent_.h_addr_list[i], addr_struct.addr, hostent_.h_length); |
} |
+ ppapi_->ReleaseResource(addr); |
} |
return &hostent_; |
} |