From f9355136d8e81de257a9d1413a293196f42e6f91 Mon Sep 17 00:00:00 2001 From: likewise Date: Wed, 8 Jun 2005 18:35:00 +0000 Subject: [PATCH] 2005-06-08 Leon Woestenberg * udp.c: Fixed memory leak; when ip_route() failed, a possibly allocated q was never de-allocated. Fixed by called ip_route() before allocating q. --- src/core/udp.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/core/udp.c b/src/core/udp.c index 948848a3..fcc8e32d 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -66,7 +66,6 @@ struct udp_pcb *udp_pcbs = NULL; static struct udp_pcb *pcb_cache = NULL; - void udp_init(void) { @@ -410,6 +409,14 @@ udp_send(struct udp_pcb *pcb, struct pbuf *p) return err; } } + /* find the outgoing network interface for this packet */ + netif = ip_route(&(pcb->remote_ip)); + /* no outgoing network interface could be found? */ + if (netif == NULL) { + LWIP_DEBUGF(UDP_DEBUG | 1, ("udp_send: No route to 0x%lx\n", pcb->remote_ip.addr)); + UDP_STATS_INC(udp.rterr); + return ERR_RTE; + } /* not enough space to add an UDP header to first pbuf in given p chain? */ if (pbuf_header(p, UDP_HLEN)) { @@ -437,14 +444,6 @@ udp_send(struct udp_pcb *pcb, struct pbuf *p) /* in UDP, 0 checksum means 'no checksum' */ udphdr->chksum = 0x0000; - /* find the outgoing network interface for this packet */ - netif = ip_route(&(pcb->remote_ip)); - /* no outgoing network interface could be found? */ - if (netif == NULL) { - LWIP_DEBUGF(UDP_DEBUG | 1, ("udp_send: No route to 0x%lx\n", pcb->remote_ip.addr)); - UDP_STATS_INC(udp.rterr); - return ERR_RTE; - } /* PCB local address is IP_ANY_ADDR? */ if (ip_addr_isany(&pcb->local_ip)) { /* use outgoing network interface IP address as source address */