I'm currently working on rebuilding NativeEthernet from scratch so that it's fully non-blocking for better performance, while working on the TCP Server code I'm running into an annoying crash I can't figure out. The only thing consistent is the type of crash that is reported, Data Access Violation, though I can't be sure why it's happening.

The new library is a little bit more complex in that you don't have to manually poll the server for connected clients or keep track of them yourself. All of the connected clients and their socket buffers are allocated from FNET's heap memory and linked by a pointer list to the server, I've kept careful track of what's allocated and deallocated to make sure it's not running out of memory and FNET has functions to check it's memory so I know that whenever this crash happens the memory is not full. It also doesn't have to do with any cache memory because it happens no matter where I allocate FNET's stack(DTCM, DMAMEM, or EXTMEM) and it doesn't take any longer to happen when I give it more memory.

I use Apache Benchmark to stress test the Server and the crash will happen after a random number of clients each time, sometimes less than 2,000 clients, sometimes not until over 20,000 connections have been made.


This CrashReport comes from this code: "if (client_list->object)"
Code:
CrashReport:
  A problem occurred at (system time) 18:57:44
  Code was executing from address 0x992
  CFSR: 82
	(DACCVIOL) Data Access Violation
	(MMARVALID) Accessed Address: 0xDF08C8F7          //The accessed address always changes between crashes
  Temperature inside the chip was 59.68 C
  Startup CPU clock speed is 600MHz
  Reboot was caused by auto reboot after fault or bad interrupt detected
This CrashReport comes from this code: "switch (tcp_ptr->tcp_state)"
Code:
CrashReport:
  A problem occurred at (system time) 19:0:1
  Code was executing from address 0x5F4
  CFSR: 82
	(DACCVIOL) Data Access Violation
	(MMARVALID) Accessed Address: 0xF43F0F60          //The accessed address always changes between crashes
  Temperature inside the chip was 59.68 C
  Startup CPU clock speed is 600MHz
  Reboot was caused by auto reboot after fault or bad interrupt detected
I'll try to explain the short pieces or code to understand more what's happening in them and after.
client_list is the pointer list of connected clients, object is a pointer that points to a specific clients object.
After passing the if check the object is then passed to a function that will give it the name tcp_ptr, tcp_state is just a normal uint32_t.

So object and tcp_ptr should reference the same object when it gets passed to the function, object is assigned in the Client class constructor and then added to the list if the Client was successfully created, everything in the list has a valid address before even being added because all the pointers and mallocs have been checked before the Client was made with placement new. I also know there is nothing wrong with the way Clients are added and removed to the pointer list since it's just a copy of what FNET uses to allocate it's own pointer lists used throughout the whole library.

Does anyone have any insight on how these pointers could be pointing to wrong addresses despite there being numerous checks in place and the fact that it happens in 1 out of thousands of iterations of the same code?