add lwIP TCP stack test with fixes: rcv_wnd tracking, FIN compensation, tmr_phase dual-counter, trace ring buffer, stats counters
This commit is contained in:
1 parent
8994d7a834
commit
7c71ef683c
9 files changed
+961
-16
No files matched your search
@@ -173,6 +173,8 @@ void u_free_impl(void* ptr, const char* location) {
|
||||
if (!ptr) return;
|
||||
u_check(ptr, "u_free", location);
|
||||
uint8_t* base = (uint8_t*)ptr - 8 - BOUNDARY_CHECK_SIZE - METADATA_SIZE;
|
||||
char* alloc_loc = (char*)base;
|
||||
uint32_t size = *(uint32_t*)(base + METADATA_SIZE + BOUNDARY_CHECK_SIZE + 4);
|
||||
// Remove from linked list (thread-safe)
|
||||
LOCK();
|
||||
void* prev = NULL;
|
||||
@@ -193,9 +195,42 @@ void u_free_impl(void* ptr, const char* location) {
|
||||
prev = curr;
|
||||
curr = *(void**)((uint8_t*)curr + NEXT_OFFSET);
|
||||
}
|
||||
size_t active_count = allocated_count;
|
||||
UNLOCK();
|
||||
if (!found) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "%s: u_free: Attempt to free unallocated or already freed pointer %p", location, ptr);
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "========================================");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "DOUBLE FREE DETECTED");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "========================================");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "Free attempt at: %s", location);
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "Pointer: %p", ptr);
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "Base: %p", (void*)base);
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "Allocated at: %s", alloc_loc);
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "User size: %u bytes", size);
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "Total allocated: %u bytes", size + 12 + 2 * BOUNDARY_CHECK_SIZE + METADATA_SIZE);
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "Active allocs: %zu", active_count);
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "--- Metadata dump at %p (%u bytes) ---", (void*)base, (unsigned)(METADATA_SIZE + BOUNDARY_CHECK_SIZE + 8));
|
||||
hex_dump(base, METADATA_SIZE + BOUNDARY_CHECK_SIZE + 8);
|
||||
if (size > 0 && size <= 1024 * 1024) {
|
||||
uint32_t dump_size = (size > 256) ? 256 : size;
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "--- User data dump at %p (%u of %u bytes) ---", ptr, dump_size, size);
|
||||
hex_dump(ptr, dump_size);
|
||||
}
|
||||
#if BACKTRACE_ENABLED
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "--- Backtrace ---");
|
||||
# if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
|
||||
void* bt_buf[32];
|
||||
int bt_size = backtrace(bt_buf, 32);
|
||||
char** bt_symbols = backtrace_symbols(bt_buf, bt_size);
|
||||
if (bt_symbols) {
|
||||
for (int i = 0; i < bt_size; i++) DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, " #%d %s", i, bt_symbols[i]);
|
||||
free(bt_symbols);
|
||||
}
|
||||
# elif defined(_WIN32)
|
||||
void* bt_buf[32];
|
||||
USHORT frames = CaptureStackBackTrace(0, 32, bt_buf, NULL);
|
||||
for (USHORT i = 0; i < frames; i++) DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, " #%d %p", i, bt_buf[i]);
|
||||
# endif
|
||||
#endif
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
free(base);
|
||||
|
||||
Reference in new issue
Block a user