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 033ddc113aa37466015b8124016ba00d062e81fa..15b8e765c88f44a56601152308fa1bfe6ab4297c 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);
     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,
 }
 
 static int resolver_beforepoll(void *sst, struct pollfd *fds, int *nfds_io,
diff --git a/site.c b/site.c
index 11690523b066ea66a707769720e92d7f70cb6d88..b6d05af74e339fc889dd04b43f055c21e1a1d85d 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;
     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)
 }
 
 static bool_t enter_new_state(struct site *st, uint32_t next)