Commit dbfaeea7 authored by Mark Andrews's avatar Mark Andrews
Browse files

fix reference counting

parent 6956928d
...@@ -85,6 +85,7 @@ static int nservers = 0; ...@@ -85,6 +85,7 @@ static int nservers = 0;
(before)->link.prev = (item); \ (before)->link.prev = (item); \
(item)->link.prev->link.next = (item); \ (item)->link.prev->link.next = (item); \
(item)->link.next = (before); \ (item)->link.next = (before); \
(item)->link.linked = 1; \
} \ } \
} while (0) } while (0)
...@@ -467,7 +468,8 @@ report(struct summary *summary) { ...@@ -467,7 +468,8 @@ report(struct summary *summary) {
*/ */
static void static void
freeitem(struct workitem * item) { freeitem(struct workitem * item) {
report(item->summary); if (item->summary)
report(item->summary);
if (item->tcpfd != 0) { if (item->tcpfd != 0) {
FD_CLR(item->tcpfd, &rfds); FD_CLR(item->tcpfd, &rfds);
FD_CLR(item->tcpfd, &wfds); FD_CLR(item->tcpfd, &wfds);
...@@ -718,7 +720,7 @@ dotest(struct workitem *item) { ...@@ -718,7 +720,7 @@ dotest(struct workitem *item) {
* Start a series of tests. * Start a series of tests.
*/ */
static void static void
check(char *zone, char *ns, char *address) { check(char *zone, char *ns, char *address, struct summary *parent) {
size_t i; size_t i;
int fd; int fd;
struct in_addr addr; struct in_addr addr;
...@@ -750,7 +752,12 @@ check(char *zone, char *ns, char *address) { ...@@ -750,7 +752,12 @@ check(char *zone, char *ns, char *address) {
summary = calloc(1, sizeof(*summary)); summary = calloc(1, sizeof(*summary));
if (summary == NULL) if (summary == NULL)
return; return;
APPEND(summaries, summary, link);
summary->tests++;
if (parent)
INSERTBEFORE(summaries, parent, summary, link);
else
APPEND(summaries, summary, link);
summary->storage = storage; summary->storage = storage;
...@@ -768,17 +775,14 @@ check(char *zone, char *ns, char *address) { ...@@ -768,17 +775,14 @@ check(char *zone, char *ns, char *address) {
continue; continue;
item = calloc(1, sizeof(*item)); item = calloc(1, sizeof(*item));
if (item == NULL) { if (item == NULL)
summary->tests++;
report(summary);
break; break;
}
summary->tests++;
item->summary = summary; item->summary = summary;
item->summary->tests++;
item->test = i; item->test = i;
dotest(item); dotest(item);
} }
report(summary);
} }
static char * static char *
...@@ -930,10 +934,6 @@ lookupa(char *zone, char *ns, struct summary *parent) { ...@@ -930,10 +934,6 @@ lookupa(char *zone, char *ns, struct summary *parent) {
summary = calloc(1, sizeof(*summary)); summary = calloc(1, sizeof(*summary));
if (summary == NULL) if (summary == NULL)
return (NULL); return (NULL);
if (parent)
INSERTBEFORE(summaries, parent, summary, link);
else
APPEND(summaries, summary, link);
ns_makecanon(zone, summary->zone, sizeof(summary->zone)); ns_makecanon(zone, summary->zone, sizeof(summary->zone));
i = strlen(summary->zone); i = strlen(summary->zone);
...@@ -945,12 +945,16 @@ lookupa(char *zone, char *ns, struct summary *parent) { ...@@ -945,12 +945,16 @@ lookupa(char *zone, char *ns, struct summary *parent) {
item = calloc(1, sizeof(*item)); item = calloc(1, sizeof(*item));
if (item == NULL) { if (item == NULL) {
freesummary(summary); free(summary);
while ((summary = HEAD(summaries)) && summary->deferred) return (NULL);
printandfree(summary);
} }
if (parent)
INSERTBEFORE(summaries, parent, summary, link);
else
APPEND(summaries, summary, link);
item->summary = summary; item->summary = summary;
summary->tests++;
dolookup(item, ns_t_a); dolookup(item, ns_t_a);
return (summary); return (summary);
} }
...@@ -970,10 +974,6 @@ lookupaaaa(char *zone, char *ns, struct summary *parent) { ...@@ -970,10 +974,6 @@ lookupaaaa(char *zone, char *ns, struct summary *parent) {
summary = calloc(1, sizeof(*summary)); summary = calloc(1, sizeof(*summary));
if (summary == NULL) if (summary == NULL)
return (NULL); return (NULL);
if (parent)
INSERTBEFORE(summaries, parent, summary, link);
else
APPEND(summaries, summary, link);
ns_makecanon(zone, summary->zone, sizeof(summary->zone)); ns_makecanon(zone, summary->zone, sizeof(summary->zone));
i = strlen(summary->zone); i = strlen(summary->zone);
...@@ -985,12 +985,16 @@ lookupaaaa(char *zone, char *ns, struct summary *parent) { ...@@ -985,12 +985,16 @@ lookupaaaa(char *zone, char *ns, struct summary *parent) {
item = calloc(1, sizeof(*item)); item = calloc(1, sizeof(*item));
if (item == NULL) { if (item == NULL) {
freesummary(summary); free(summary);
while ((summary = HEAD(summaries)) && summary->deferred) return (NULL);
printandfree(summary);
} }
if (parent)
INSERTBEFORE(summaries, parent, summary, link);
else
APPEND(summaries, summary, link);
item->summary = summary; item->summary = summary;
summary->tests++;
dolookup(item, ns_t_aaaa); dolookup(item, ns_t_aaaa);
return (summary); return (summary);
} }
...@@ -1007,7 +1011,6 @@ lookupns(char *zone) { ...@@ -1007,7 +1011,6 @@ lookupns(char *zone) {
summary = calloc(1, sizeof(*summary)); summary = calloc(1, sizeof(*summary));
if (summary == NULL) if (summary == NULL)
return; return;
APPEND(summaries, summary, link);
ns_makecanon(zone, summary->zone, sizeof(summary->zone)); ns_makecanon(zone, summary->zone, sizeof(summary->zone));
i = strlen(summary->zone); i = strlen(summary->zone);
...@@ -1015,11 +1018,11 @@ lookupns(char *zone) { ...@@ -1015,11 +1018,11 @@ lookupns(char *zone) {
item = calloc(1, sizeof(*item)); item = calloc(1, sizeof(*item));
if (item == NULL) { if (item == NULL) {
freesummary(summary); free(summary);
while ((summary = HEAD(summaries)) && summary->deferred) return;
printandfree(summary);
} }
APPEND(summaries, summary, link);
item->summary = summary; item->summary = summary;
dolookup(item, ns_t_ns); dolookup(item, ns_t_ns);
} }
...@@ -1152,7 +1155,8 @@ process(struct workitem *item, unsigned char *buf, int n) { ...@@ -1152,7 +1155,8 @@ process(struct workitem *item, unsigned char *buf, int n) {
if (rdlen != 4) if (rdlen != 4)
goto err; goto err;
inet_ntop(AF_INET, cp, addrbuf, sizeof(addrbuf)); inet_ntop(AF_INET, cp, addrbuf, sizeof(addrbuf));
check(item->summary->zone, item->summary->ns, addrbuf); check(item->summary->zone, item->summary->ns, addrbuf,
item->summary);
item->summary->done = 1; item->summary->done = 1;
} }
if (item->type == ns_t_aaaa && type == ns_t_aaaa && if (item->type == ns_t_aaaa && type == ns_t_aaaa &&
...@@ -1161,7 +1165,8 @@ process(struct workitem *item, unsigned char *buf, int n) { ...@@ -1161,7 +1165,8 @@ process(struct workitem *item, unsigned char *buf, int n) {
if (rdlen != 16) if (rdlen != 16)
goto err; goto err;
inet_ntop(AF_INET6, cp, addrbuf, sizeof(addrbuf)); inet_ntop(AF_INET6, cp, addrbuf, sizeof(addrbuf));
check(item->summary->zone, item->summary->ns, addrbuf); check(item->summary->zone, item->summary->ns, addrbuf,
item->summary);
item->summary->done = 1; item->summary->done = 1;
} }
if (item->type == ns_t_ns && type == ns_t_ns && if (item->type == ns_t_ns && type == ns_t_ns &&
...@@ -1184,6 +1189,8 @@ process(struct workitem *item, unsigned char *buf, int n) { ...@@ -1184,6 +1189,8 @@ process(struct workitem *item, unsigned char *buf, int n) {
summarya->xlink = summaryaaaa; summarya->xlink = summaryaaaa;
summaryaaaa->xlink = summarya; summaryaaaa->xlink = summarya;
} }
if (summarya) report(summarya);
if (summaryaaaa) report(summaryaaaa);
} }
cp += rdlen; cp += rdlen;
if (type == ns_t_soa && if (type == ns_t_soa &&
...@@ -1578,7 +1585,7 @@ readstdin(int fd) { ...@@ -1578,7 +1585,7 @@ readstdin(int fd) {
} }
n = sscanf(line, "%1024s%1024s%1024s", zone, ns, address); n = sscanf(line, "%1024s%1024s%1024s", zone, ns, address);
if (n == 3) if (n == 3)
check(zone, ns, address); check(zone, ns, address, NULL);
if (n == 2) { if (n == 2) {
struct summary *summarya, *summaryaaaa; struct summary *summarya, *summaryaaaa;
...@@ -1592,6 +1599,8 @@ readstdin(int fd) { ...@@ -1592,6 +1599,8 @@ readstdin(int fd) {
summarya->xlink = summaryaaaa; summarya->xlink = summaryaaaa;
summaryaaaa->xlink = summarya; summaryaaaa->xlink = summarya;
} }
if (summarya) report(summarya);
if (summaryaaaa) report(summaryaaaa);
} }
if (n == 1) if (n == 1)
lookupns(zone); lookupns(zone);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment