diff --git a/ares/ares_init.c b/ares/ares_init.c
index 2f320a2fa0874ec595a97bcbc3b04256a075a396..b26a4340def9e61e135bf5befb5f5063c24ed5fd 100644
--- a/ares/ares_init.c
+++ b/ares/ares_init.c
@@ -93,6 +93,16 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
   struct server_state *server;
   struct timeval tv;
 
+#ifdef CURLDEBUG
+  const char *env = getenv("CARES_MEMDEBUG");
+
+  if (env)
+    curl_memdebug(env);
+  env = getenv("CARES_MEMLIMIT");
+  if (env)
+    curl_memlimit(atoi(env));
+#endif
+
   channel = malloc(sizeof(struct ares_channeldata));
   if (!channel)
     return ARES_ENOMEM;