Skip to content

[BUG] Freed memory is being used #1110

@ATDOR-RIH

Description

@ATDOR-RIH

Describe the bug
This bug releates to #570 which was solved in #707.

The bug was fixed by clearing pPassQueued and pPassAccept.
By calling

vSocketCloseNextTime( pxSocket );

and
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 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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions