-
Notifications
You must be signed in to change notification settings - Fork 207
Description
Describe the bug
This bug releates to #570 which was solved in #707.
The bug was fixed by clearing pPassQueued and pPassAccept.
By calling
FreeRTOS-Plus-TCP/source/FreeRTOS_TCP_IP.c
Line 461 in ef14a08
| vSocketCloseNextTime( pxSocket ); |
and
FreeRTOS-Plus-TCP/source/FreeRTOS_IP_Timers.c
Line 309 in ef14a08
| vSocketCloseNextTime( NULL ); |
the socket gets freed, however the parent socket might still have a reference to the socket.
When the user task calls FreeRTOS_accept it will check if the pPassAccept bit is set. If not FreeRTOS_accept will return NULL and everything is fine.
But the memory is freed already, so there is no guarantee that pPassAccept is still cleared.
Target
- Development board: [e.g. HiFive11 RevB]
- Instruction Set Architecture: ARM CortexA7
- IDE and version: Eclipse + CMake
- Toolchain and version: arm-none-eabi-gcc 10.3.1
Host
- Host OS: Ubuntu
- Version: 18.04
To Reproduce
The device acts as web server and the error happened by continuously refreshing the web site using https.
It did not happen when using http.
Expected behavior
Do not leave references to freed memory.
Screenshots
None
Wireshark logs
None
Additional context
Added log lines:
- logll_debug( BASE_FILE_NAME, "FreeRTOS_socket 0x%x", xReturn ); after
FreeRTOS-Plus-TCP/source/FreeRTOS_Sockets.c
Line 761 in ef14a08
xReturn = pxSocket; - logll_debug( BASE_FILE_NAME, "FreeRTOS_bind 0x%x %li", xSocket, xReturn ); before
FreeRTOS-Plus-TCP/source/FreeRTOS_Sockets.c
Line 1773 in ef14a08
return xReturn; - logll_debug( BASE_FILE_NAME, "FreeRTOS_closesocket - 0x%x", xSocket ); after
FreeRTOS-Plus-TCP/source/FreeRTOS_Sockets.c
Line 2019 in ef14a08
xCloseEvent.pvData = xSocket; - logll_debug( BASE_FILE_NAME, "vSocketClose 0x%x", pxSocket ); before
FreeRTOS-Plus-TCP/source/FreeRTOS_Sockets.c
Line 2175 in ef14a08
vPortFreeSocket( pxSocket ); if( pxParentSocket->u.xTCP.pxPeerSocket != NULL ) { logll_debug( BASE_FILE_NAME, "pxClientSocket = pxParentSocket->u.xTCP.pxPeerSocket; 0x%x 0x%x 0x%x", pxClientSocket, pxParentSocket, pxParentSocket->u.xTCP.pxPeerSocket ); }beforeFreeRTOS-Plus-TCP/source/FreeRTOS_Sockets.c
Line 3892 in ef14a08
pxClientSocket = pxParentSocket->u.xTCP.pxPeerSocket; if( pxParentSocket != NULL ) { logll_debug( BASE_FILE_NAME, "pxClientSocket = pxParentSocket; 0x%x 0x%x", pxClientSocket, pxParentSocket ); }beforeFreeRTOS-Plus-TCP/source/FreeRTOS_Sockets.c
Line 3896 in ef14a08
pxClientSocket = pxParentSocket; - logll_debug( BASE_FILE_NAME, "pxClientSocket = NULL;" ); before
FreeRTOS-Plus-TCP/source/FreeRTOS_Sockets.c
Line 3910 in ef14a08
pxClientSocket = NULL; if( pxClientSocket != NULL && pxClientSocket != FREERTOS_INVALID_SOCKET ) { logll_debug( BASE_FILE_NAME, "FreeRTOS_accept 0x%x 0x%x", pxSocket, pxClientSocket ); }beforeFreeRTOS-Plus-TCP/source/FreeRTOS_Sockets.c
Line 4059 in ef14a08
return pxClientSocket; - logll_debug( BASE_FILE_NAME, "FreeRTOS_listen 0x%x %li", xSocket, xResult ); before
FreeRTOS-Plus-TCP/source/FreeRTOS_Sockets.c
Line 4756 in ef14a08
return xResult; - logll_debug( BASE_FILE_NAME, "vSocketCloseNextTime 0x%x 0x%x", xSocketToClose, pxSocket ); after
FreeRTOS-Plus-TCP/source/FreeRTOS_TCP_IP.c
Line 111 in ef14a08
( void ) vSocketClose( xSocketToClose ); else if( pxSocket != NULL ) { logll_debug( BASE_FILE_NAME, "vSocketCloseNextTime set xSocketToClose 0x%x 0x%x", xSocketToClose, pxSocket ); }afterFreeRTOS-Plus-TCP/source/FreeRTOS_TCP_IP.c
Line 112 in ef14a08
} - logll_debug( BASE_FILE_NAME, "xParent = pxSocket->u.xTCP.pxPeerSocket; 0x%x 0x%x 0x%x", xParent, pxSocket, pxSocket->u.xTCP.pxPeerSocket ); after
FreeRTOS-Plus-TCP/source/FreeRTOS_TCP_IP.c
Line 325 in ef14a08
xParent = pxSocket->u.xTCP.pxPeerSocket; - logll_debug( BASE_FILE_NAME, "xParent->u.xTCP.pxPeerSocket = pxSocket; 0x%x 0x%x", xParent, pxSocket ); before
FreeRTOS-Plus-TCP/source/FreeRTOS_TCP_IP.c
Line 345 in ef14a08
xParent->u.xTCP.pxPeerSocket = pxSocket; - logll_debug( BASE_FILE_NAME, "pxSocket->u.xTCP.pxPeerSocket = pxFound; 0x%x 0x%x", pxSocket, pxFound ); before
FreeRTOS-Plus-TCP/source/FreeRTOS_TCP_IP.c
Line 718 in ef14a08
pxSocket->u.xTCP.pxPeerSocket = pxFound;
logll_debug is a function which writes the given text to a serial interface which is connected to the computer used for debugging.
Format of the log line: (file name provided by macro BASE_FILE_NAME);(log level 1 in case of debug);(monotonic time in ms);(log message)
Log lines where the described bug happens:
Creation of socket.
D:FreeRTOS_Sockets.c;1;38081;FreeRTOS_socket 0x7035c548
D:FreeRTOS_TCP_IP.c;1;38113;xParent = pxSocket->u.xTCP.pxPeerSocket; 0x70284130 0x7035c548 0x70284130
D:FreeRTOS_TCP_IP.c;1;38113;xParent->u.xTCP.pxPeerSocket = pxSocket; 0x70284130 0x7035c548
IP-Task is closing the socket.
D:FreeRTOS_TCP_IP.c;1;38130;vSocketCloseNextTime set xSocketToClose 0x0 0x7035c548
D:FreeRTOS_Sockets.c;1;38130;vSocketClose 0x7035c548
D:FreeRTOS_TCP_IP.c;1;38130;vSocketCloseNextTime 0x7035c548 0x0
Call FreeRTOS_accept from user task. The memory was not overwritten yet, so prvAcceptWaitClient returns NULL.
D:FreeRTOS_Sockets.c;1;38706;pxClientSocket = pxParentSocket->u.xTCP.pxPeerSocket; 0x0 0x70284130 0x7035c548
Full logs
logs.txt
Config
ipconfig.txt