From 31d8988f89699aa357b0468a700483ea340e9da9 Mon Sep 17 00:00:00 2001 From: MinghaoWang Date: Fri, 21 Mar 2025 22:34:52 +0300 Subject: [PATCH] Apply patch #10358: preserve dhcp memory type flag --- src/core/ipv4/dhcp.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index 12e00683..c149dd12 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -773,9 +773,6 @@ dhcp_set_struct(struct netif *netif, struct dhcp *dhcp) * @ingroup dhcp4 * Removes a struct dhcp from a netif. * - * ATTENTION: Only use this when not using dhcp_set_struct() to allocate the - * struct dhcp since the memory is passed back to the heap. - * * @param netif the netif from which to remove the struct dhcp */ void dhcp_cleanup(struct netif *netif) @@ -811,6 +808,7 @@ dhcp_start(struct netif *netif) { struct dhcp *dhcp; err_t result; + u8_t saved_flags; LWIP_ASSERT_CORE_LOCKED(); LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG;); @@ -846,9 +844,10 @@ dhcp_start(struct netif *netif) /* dhcp is cleared below, no need to reset flag*/ } - /* clear data structure */ + /* clear data structure but preserve DHCP_FLAG_EXTERNAL_MEM for dhcp_cleanup() */ + saved_flags = dhcp->flags; memset(dhcp, 0, sizeof(struct dhcp)); - /* dhcp_set_state(&dhcp, DHCP_STATE_OFF); */ + dhcp->flags = saved_flags & DHCP_FLAG_EXTERNAL_MEM; #if LWIP_DHCP_DOES_ACD_CHECK