@@ -1358,7 +1358,6 @@ dhcp_stop(struct netif *netif)
13581358
13591359 LWIP_ASSERT ("reply wasn't freed" , dhcp -> msg_in == NULL );
13601360 dhcp_set_state (dhcp , DHCP_STATE_OFF );
1361-
13621361 if (dhcp -> pcb_allocated != 0 ) {
13631362 dhcp_dec_pcb_refcount (); /* free DHCP PCB if not needed any more */
13641363 dhcp -> pcb_allocated = 0 ;
@@ -1817,7 +1816,15 @@ dhcp_create_msg(struct netif *netif, struct dhcp *dhcp, u8_t message_type)
18171816 xid = DHCP_GLOBAL_XID ;
18181817 xid_initialised = !xid_initialised ;
18191818 }
1820- #endif
1819+ #endif
1820+
1821+ /* Clear any existing message before creating a new one */
1822+ if (dhcp -> p_out != NULL ) {
1823+ pbuf_free (dhcp -> p_out );
1824+ dhcp -> p_out = NULL ;
1825+ dhcp -> msg_out = NULL ;
1826+ }
1827+
18211828 LWIP_ERROR ("dhcp_create_msg: netif != NULL" , (netif != NULL ), return ERR_ARG ;);
18221829 LWIP_ERROR ("dhcp_create_msg: dhcp != NULL" , (dhcp != NULL ), return ERR_VAL ;);
18231830 LWIP_ASSERT ("dhcp_create_msg: dhcp->p_out == NULL" , dhcp -> p_out == NULL );
@@ -1899,9 +1906,10 @@ static void
18991906dhcp_delete_msg (struct dhcp * dhcp )
19001907{
19011908 LWIP_ERROR ("dhcp_delete_msg: dhcp != NULL" , (dhcp != NULL ), return ;);
1902- LWIP_ASSERT ("dhcp_delete_msg: dhcp->p_out != NULL" , dhcp -> p_out != NULL );
1903- LWIP_ASSERT ("dhcp_delete_msg: dhcp->msg_out != NULL" , dhcp -> msg_out != NULL );
1909+ /* LWIP_ASSERT("dhcp_delete_msg: dhcp->p_out != NULL", dhcp->p_out != NULL); */
1910+ /* LWIP_ASSERT("dhcp_delete_msg: dhcp->msg_out != NULL", dhcp->msg_out != NULL); */
19041911 if (dhcp -> p_out != NULL ) {
1912+ LWIP_ASSERT ("dhcp_delete_msg: dhcp->msg_out != NULL" , dhcp -> msg_out != NULL );
19051913 pbuf_free (dhcp -> p_out );
19061914 }
19071915 dhcp -> p_out = NULL ;
0 commit comments