Hi Martin,
I'm pretty sure that I have discovered the culprit in my MQX crash problem. It appears to be the calls to HTTPSRV_cgi_read() that my CGI service function makes to retrieve the CGI message into my temp buffer for processing. All of my incoming CGI messages are served by a single function I wrote that examines the start of the message and calls the appropriate function to decode and act on the received message. As a troubleshooting step I removed all code from this function except for the code that allocated and freed the temp buffer then exited. Doing this, my service function serviced over 10,000 received messages with no crashes. I next added code to set the temp buffer to all 0x00 and then all 0xFF bytes before it was freed (to ensure the buffer memory area was ok to write to), still no crashes. Finally I added in the code to call HTTPSRV_cgi_read() and store the received message in the temp buffer and MQX started crashing regularly.
I'm posting the code for my stripped down CGI service function as I used it for these tests so you can see what I'm doing. It appears that the problem is not with repeatedly allocating and freeing a temp buffer, or with the memory space provided by _mem_alloc_system(), the problem only shows up when HTTPSRV_cgi_read() is called to load the received message data into the temp buffer. Here's my stripped down CGI service function:
mqx_int CGI_ParseMsg(HTTPSRV_CGI_REQ_STRUCT *param)
{
uint_32 lTotalMsgBytes;
uint_32 lReadLength, lBytesRead;
static uint_32 lCallCounter = 0;
char_ptr cBuf = NULL;
char_ptr cBufPtr = NULL;
//
//----------------------------------------------------------------------------
if(param->request_method != HTTPSRV_REQ_POST)
return(0);
//Attempt to allocate cBuf to store the received data
//----------------------------------------------------------------------------
lTotalMsgBytes = param->content_length;
cBuf = _mem_alloc_system(lTotalMsgBytes);
if(cBuf == NULL)
return(0);
//Read in the data until all bytes (per param->content_length) are received
//----------------------------------------------------------------------------
cBufPtr = cBuf; //Use cBufPtr as a movable temp pointer so cBuf is not changed and can be freed
lBytesRead = 0;
while(param->content_length > 0) //<-- *** Comment out this loop and things stop crashing ***
{
lReadLength = HTTPSRV_cgi_read(param->ses_handle, cBufPtr, (lTotalMsgBytes - lBytesRead));
param->content_length -= lReadLength;
cBufPtr += lReadLength;
lBytesRead += lReadLength;
}
if(_mem_free(cBuf) != MQX_OK)
return(0);
lCallCounter++; //Used to track how many incoming msgs this function has serviced
return(0);
}
I'm calling HTTPSRV_cgi_read() in a loop based on the example in the ...\rtcs\examples\httpsrv\cgi.c file. Do you see that I may be using it incorrectly? It usually works just fine. My service function may properly service dozens to hundreds of received CGI messages then, seemingly at random, MQX will crash as illustrated in my earlier posts. Either I'm using HTTPSRV_cgi_read() incorrectly or it's got a bug that is crashing MQX. Any other possibilities? Thanks for your help Martin, I appreciate it.
Best Regards,
Tim