Memory error on DHCP retry

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Memory error on DHCP retry

ricardoschoof
When setting up my STM32H7 with LwIP 2.1.2, FreeRTOS 10.2.0. I try to start
my device as a DHCP client.

The first try I see a DHCP Discover packet I Wireshark. After a second the
time-out kicks in and the device will start a retry. This will result in a
hardfault error.

So far I have narrowed it down to the LWIP function: dhcp_create_msg in
dhcp.c. The values dhcp->xid and p_out->next share the same address

First try:
&(dhcp->xid) = 0x20003DB8
&(p_out->next) = 0x20003DF4

Retry:
&(dhcp->xid) = 0x20003DB8
&(p_out->next) = 0x20003DB8

When the new xid is set this will automatically set the next pointer, in the
lowlevel_output following loop contains:
for(q = p; q != NULL; q = q->next)


The p_out->next (dhcp->xid) won't be NULL and will try to read the data
causing a hardfaulterror
Is there something I am missing?



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Memory error on DHCP retry

ricardoschoof
I have an update:
When adding
#define MEM_LIBC_MALLOC (1)
in my lwipopts.h the retry will pass.

The problem seems to be in mem.c. I have debugged some more and have found
that the application runs as follows:

1) Creating DHCP struct (as part of dhcp_start -> mem_malloc) assign address
0x20003DB8

2) DHCP Discover message (dhcp_create_msg->pbuf_alloc -> mem_malloc) assign
address 0x20003DF4
This message will be freed afterwards

3) DHCP Discover retry (dhcp_create_msg->pbuf_alloc -> mem_malloc) assign
address 0x20003DB8

No other malloc / free calls are made between these 3 steps.

Cheers
Ricardo



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Memory error on DHCP retry

ricardoschoof
Final update:
Problem was an error of me: *somehow* mem_init and memp_init were also
called after dhcp_start. This caused some data disappear and reused for the
new buffers.

Cheers!



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users