@@ -285,10 +285,7 @@ context_query_common (struct resolv_context *ctx,
unsigned char *answer, int anslen)
{
if (ctx == NULL)
- {
- RES_SET_H_ERRNO (&_res, NETDB_INTERNAL);
- return -1;
- }
+ return -1;
int result = __res_context_query (ctx, name, class, type, answer, anslen,
NULL, NULL, NULL, NULL, NULL);
__resolv_context_put (ctx);
@@ -524,10 +521,7 @@ context_search_common (struct resolv_context *ctx,
unsigned char *answer, int anslen)
{
if (ctx == NULL)
- {
- RES_SET_H_ERRNO (&_res, NETDB_INTERNAL);
- return -1;
- }
+ return -1;
int result = __res_context_search (ctx, name, class, type, answer, anslen,
NULL, NULL, NULL, NULL, NULL);
__resolv_context_put (ctx);
@@ -603,10 +597,7 @@ context_querydomain_common (struct resolv_context *ctx,
unsigned char *answer, int anslen)
{
if (ctx == NULL)
- {
- RES_SET_H_ERRNO (&_res, NETDB_INTERNAL);
- return -1;
- }
+ return -1;
int result = __res_context_querydomain (ctx, name, domain, class, type,
answer, anslen,
NULL, NULL, NULL, NULL, NULL);
@@ -681,10 +672,7 @@ context_hostalias_common (struct resolv_context *ctx,
const char *name, char *dst, size_t siz)
{
if (ctx == NULL)
- {
- RES_SET_H_ERRNO (&_res, NETDB_INTERNAL);
- return NULL;
- }
+ return NULL;
const char *result = __res_context_hostalias (ctx, name, dst, siz);
__resolv_context_put (ctx);
return result;
@@ -554,10 +554,7 @@ context_send_common (struct resolv_context *ctx,
unsigned char *ans, int anssiz)
{
if (ctx == NULL)
- {
- RES_SET_H_ERRNO (&_res, NETDB_INTERNAL);
- return -1;
- }
+ return -1;
int result = __res_context_send (ctx, buf, buflen, NULL, 0, ans, anssiz,
NULL, NULL, NULL, NULL, NULL);
__resolv_context_put (ctx);
@@ -22,6 +22,7 @@
#include <assert.h>
#include <errno.h>
+#include <netdb.h>
#include <stdlib.h>
#include <stdio.h>
@@ -126,13 +127,18 @@ maybe_init (struct resolv_context *ctx, bool preinit)
}
/* Allocate a new context object and initialize it. The object is put
- on the current list. */
+ on the current list. On memory allocation failure, h_errno is set
+ to NETDB_INTERNAL. */
static struct resolv_context *
context_alloc (struct __res_state *resp)
{
struct resolv_context *ctx = malloc (sizeof (*ctx));
if (ctx == NULL)
- return NULL;
+ {
+ resp->res_h_errno = NETDB_INTERNAL;
+ __set_h_errno (NETDB_INTERNAL);
+ return NULL;
+ }
ctx->resp = resp;
ctx->conf = __resolv_conf_get (resp);
ctx->__refcount = 1;