dovecot-2.2: lib-dns: Close dns-client fd before calling callback.
dovecot at dovecot.org
dovecot at dovecot.org
Fri Oct 11 21:37:13 EEST 2013
details: http://hg.dovecot.org/dovecot-2.2/rev/a677a70e420c
changeset: 16846:a677a70e420c
user: Timo Sirainen <tss at iki.fi>
date: Fri Oct 11 21:36:21 2013 +0300
description:
lib-dns: Close dns-client fd before calling callback.
Just in case the callback is slow and keeps the fd unnecessarily long open.
diffstat:
src/lib-dns/dns-lookup.c | 25 ++++++++++++++++++-------
1 files changed, 18 insertions(+), 7 deletions(-)
diffs (56 lines):
diff -r 086c75564ba0 -r a677a70e420c src/lib-dns/dns-lookup.c
--- a/src/lib-dns/dns-lookup.c Fri Oct 11 20:03:06 2013 +0300
+++ b/src/lib-dns/dns-lookup.c Fri Oct 11 21:36:21 2013 +0300
@@ -36,6 +36,21 @@
static void dns_lookup_free(struct dns_lookup **_lookup);
+static void dns_lookup_close(struct dns_lookup *lookup)
+{
+ if (lookup->to != NULL)
+ timeout_remove(&lookup->to);
+ if (lookup->io != NULL)
+ io_remove(&lookup->io);
+ if (lookup->input != NULL)
+ i_stream_destroy(&lookup->input);
+ if (lookup->fd != -1) {
+ if (close(lookup->fd) < 0)
+ i_error("close(%s) failed: %m", lookup->path);
+ lookup->fd = -1;
+ }
+}
+
static int dns_lookup_input_line(struct dns_lookup *lookup, const char *line)
{
struct dns_lookup_result *result = &lookup->result;
@@ -122,6 +137,7 @@
}
if (ret != 0) {
dns_lookup_save_msecs(lookup);
+ dns_lookup_close(lookup);
lookup->callback(result, lookup->context);
dns_lookup_free(&lookup);
}
@@ -131,6 +147,7 @@
{
lookup->result.error = "DNS lookup timed out";
+ dns_lookup_close(lookup);
lookup->callback(&lookup->result, lookup->context);
dns_lookup_free(&lookup);
}
@@ -209,13 +226,7 @@
*_lookup = NULL;
- if (lookup->to != NULL)
- timeout_remove(&lookup->to);
- io_remove(&lookup->io);
- i_stream_destroy(&lookup->input);
- if (close(lookup->fd) < 0)
- i_error("close(%s) failed: %m", lookup->path);
-
+ dns_lookup_close(lookup);
i_free(lookup->name);
i_free(lookup->ips);
i_free(lookup->path);
More information about the dovecot-cvs
mailing list