Skip to content

Commit

Permalink
dns/client: fix getaddrinfo err handling and mem_ref dnsc (#929)
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers authored Aug 31, 2023
1 parent e4ae3dd commit 40242e5
Showing 1 changed file with 24 additions and 4 deletions.
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

0 comments on commit 40242e5

Please sign in to comment.