Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dns/client: fix getaddrinfo err handling and mem_ref dnsc #929

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions src/dns/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -914,33 +914,53 @@ static void getaddrinfo_h(int err, void *arg)
tmr_start(&q->tmr_ttl, GETADDRINFO_TTL * 1000, ttl_timeout_handler, q);

out:
mem_deref(dq->name);
mem_deref(dq);
}


static void dq_deref(void *arg)
{
struct dnsquery *dq = arg;

mem_deref(dq->dnsc);
mem_deref(dq->name);
}


static int query_getaddrinfo(struct dns_query *q)
{
int err;

struct dnsquery *dq = mem_zalloc(sizeof(struct dnsquery), NULL);
struct dnsquery *dq = mem_zalloc(sizeof(struct dnsquery), dq_deref);
if (!dq)
return ENOMEM;

str_dup(&dq->name, q->name);
err = str_dup(&dq->name, q->name);
if (err)
goto out;

dq->type = q->type;
dq->hdr.id = q->id;
dq->hdr.opcode = q->opcode;
dq->dnsclass = q->dnsclass;
dq->dnsc = q->dnsc;
dq->dnsc = mem_ref(q->dnsc);

dq->rrlv = mem_alloc(sizeof(struct list), NULL);
if (!dq->rrlv) {
err = ENOMEM;
goto out;
}

list_init(dq->rrlv);

err = re_thread_async(async_getaddrinfo, getaddrinfo_h, dq);
if (err)
DEBUG_WARNING("re_thread_async: %m\n", err);

out:
if (err)
mem_deref(dq);

return err;
}

Expand Down