From 668d4611042cce5ad9bc2604d29e3c6ad382a3c5 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 13 Nov 2015 16:01:38 +0800 Subject: [PATCH] dns: Fix dns_alloc_pcb for reuse an existing one case The logic to use an already existing pcb is wrong because the idx never advanced in the for loop, so it keep checking the same dns_pcbs[idx] for each loop iteration. Fix it. Signed-off-by: Axel Lin --- src/core/dns.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/dns.c b/src/core/dns.c index 3c019a3e..d1e4c21d 100644 --- a/src/core/dns.c +++ b/src/core/dns.c @@ -851,8 +851,7 @@ dns_alloc_pcb(void) } /* if we come here, creating a new UDP pcb failed, so we have to use an already existing one */ - idx = dns_last_pcb_idx + 1; - for (i = 0; i < DNS_MAX_SOURCE_PORTS; i++) { + for (i = 0, idx = dns_last_pcb_idx + 1; i < DNS_MAX_SOURCE_PORTS; i++, idx++) { if (idx >= DNS_MAX_SOURCE_PORTS) { idx = 0; }