I spent quite a few hours tracking down an issue with the UDP receive
callback, so I'm sending the solution to this list for people who
may run into the same issue. It probably doesn't qualify as a bug.
In the UDP receive callback we get (among others) a pointer to a pbuf
chain and a pointer to the ip address of the other side as arguments.
My callback is implemented as follows:
* unpack the pbuf chain into a linear buffer and free the pbuf chain
* do something with the data
* construct a response, allocate a pbuf and put it in this pbuf chain
* send the response to the other side using udp_sendto, to the ip
address that we got as an argument to the receive callback.
To me, this seems like a fairly typical use-case of the UDP receive
However, it did not work. It turns out that the ip address pointer
points somewhere into the pbuf chain, so it is no longer valid when
the pbuf if freed, re-allocated and filled with response data.
To make it more confusing, this made me run into a memory leak in
udp.c (not released yet, but fixed in v 1.67 in CVS).
I fixed it by explicitly copying the value of the IP address argument
of the UDP receive callback in a local variable and to use that for
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org