dns: use alloca instead of malloc to fix memleak in dns_send_answer()
authorFelix Fietkau <nbd@openwrt.org>
Tue, 3 Jun 2014 21:23:12 +0000 (23:23 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Tue, 3 Jun 2014 21:23:12 +0000 (23:23 +0200)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
dns.c

diff --git a/dns.c b/dns.c
index 517825b..cf8c3d5 100644 (file)
--- a/dns.c
+++ b/dns.c
@@ -182,10 +182,7 @@ dns_send_answer(struct uloop_fd *u, char *answer)
        h.answers = __cpu_to_be16(dns_answer_cnt);
        h.flags = __cpu_to_be16(0x8400);
 
        h.answers = __cpu_to_be16(dns_answer_cnt);
        h.flags = __cpu_to_be16(0x8400);
 
-       iov = malloc(sizeof(struct iovec) * ((dns_answer_cnt * 3) + 1));
-       if (!iov)
-               return;
-
+       iov = alloca(sizeof(struct iovec) * ((dns_answer_cnt * 3) + 1));
        iov[0].iov_base = &h;
        iov[0].iov_len = sizeof(struct dns_header);
 
        iov[0].iov_base = &h;
        iov[0].iov_len = sizeof(struct dns_header);