chiark / gitweb /
site: Fix bugs when resolver request submission fails
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 13 May 2014 20:08:03 +0000 (21:08 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 18 May 2014 13:53:12 +0000 (14:53 +0100)
Previously, if adns_submit failed:
 - the struct query in resolver.c was leaked
 - nothing was logged
 - the return value from resolver->request was ignored so the site
   state machine would hang

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
---
Changes in v2:
  * Fixed typo in commit message.

resolver.c
site.c

index 033ddc1..15b8e76 100644 (file)
@@ -50,8 +50,15 @@ static bool_t resolve_request(void *sst, cstring_t name,
     q->answer=cb;
 
     rv=adns_submit(st->ast, name, adns_r_a, 0, q, &q->query);
+    if (rv) {
+        Message(M_WARNING,
+               "resolver: failed to submit lookup for %s: %s",name,
+               adns_strerror(rv));
+       free(q);
+       return False;
+    }
 
-    return rv==0;
+    return True;
 }
 
 static int resolver_beforepoll(void *sst, struct pollfd *fds, int *nfds_io,
diff --git a/site.c b/site.c
index 1169052..b6d05af 100644 (file)
--- a/site.c
+++ b/site.c
@@ -1291,9 +1291,8 @@ static bool_t enter_state_resolve(struct site *st)
     state_assert(st,st->state==SITE_RUN);
     slog(st,LOG_STATE,"entering state RESOLVE");
     st->state=SITE_RESOLVE;
-    st->resolver->request(st->resolver->st,st->address,
-                         site_resolve_callback,st);
-    return True;
+    return st->resolver->request(st->resolver->st,st->address,
+                                site_resolve_callback,st);
 }
 
 static bool_t enter_new_state(struct site *st, uint32_t next)