[En-Nut-Discussion] How handle out of memory cases in NutNetBufAllocData?
Malte Marwedel
m.marwedel at onlinehome.de
Sun Feb 7 20:04:02 CET 2010
Hello,
I finally figured out, why my program sometimes crashed.
NutNetBufFree() frees invalid memory regions, because it does not check
if the parameter nb is NULL (NutHeapFree(nb->nb_dl.vp);)
NutTcpOutput() calls NutNetBufFree() and may get the data from
NutNetBufClone().
NutNetBufClone() returns NULL if NutNetBufAllocData() returns something
!= 0.
NutNetBufAllocData() returns -1 if NutHeapAlloc() fails.
NutHeapAlloc() failed, because all memory was temporary used.
So at least in one function a check for errors is missing.
For a simple work-around, I added
if (nb == NULL) {
return;
}
to NutNetBufFree(). This avoids memory corruption, but data connections
are still breaking if this happens.
Could it be ok (side effects?), to sleep in NutNetBufAllocData() (with a
timeout to prevent deadlocks) until some space is available?
The low memory situations always last only a few milliseconds, if there
are several connections running.
Most of the time, there are around 10K free heap - NutNetBufAllocData()
needs ~1,5K.
Or does anyone have a better idea (beside avoiding having two
connections, freeing RAM, adding more RAM, reducing the TCP/IP buffer size)?
Regards,
Malte
More information about the En-Nut-Discussion
mailing list