Skip to content

Commit 9361603

Browse files
authored
Merge pull request wolfSSL#8071 from JacobBarthelmeh/static
display heap pointer with debug enabled
2 parents 165b4af + bc56129 commit 9361603

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

wolfcrypt/src/memory.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,8 @@ void* wolfSSL_Malloc(size_t size, void* heap, int type)
10301030
#endif
10311031

10321032
#ifdef WOLFSSL_DEBUG_MEMORY
1033-
fprintf(stderr, "Alloc: %p -> %u at %s:%d\n", res, (word32)size, func, line);
1033+
fprintf(stderr, "[HEAP %p] Alloc: %p -> %u at %s:%d\n", heap,
1034+
res, (word32)size, func, line);
10341035
#endif
10351036
#else
10361037
WOLFSSL_MSG("No heap hint found to use and no malloc");
@@ -1097,8 +1098,8 @@ void* wolfSSL_Malloc(size_t size, void* heap, int type)
10971098
}
10981099
#ifdef WOLFSSL_DEBUG_STATIC_MEMORY
10991100
else {
1100-
fprintf(stderr, "Size: %lu, Empty: %d\n", (unsigned long) size,
1101-
mem->sizeList[i]);
1101+
fprintf(stderr, "Size: %lu, Empty: %d\n",
1102+
(unsigned long) size, mem->sizeList[i]);
11021103
}
11031104
#endif
11041105
}
@@ -1114,7 +1115,8 @@ void* wolfSSL_Malloc(size_t size, void* heap, int type)
11141115

11151116
#ifdef WOLFSSL_DEBUG_MEMORY
11161117
pt->szUsed = size;
1117-
fprintf(stderr, "Alloc: %p -> %lu at %s:%d\n", pt->buffer, size, func, line);
1118+
fprintf(stderr, "[HEAP %p] Alloc: %p -> %lu at %s:%d\n", heap,
1119+
pt->buffer, size, func, line);
11181120
#endif
11191121
#ifdef WOLFSSL_STATIC_MEMORY_DEBUG_CALLBACK
11201122
if (DebugCb) {
@@ -1143,8 +1145,8 @@ void* wolfSSL_Malloc(size_t size, void* heap, int type)
11431145
WOLFSSL_MSG("ERROR ran out of static memory");
11441146
res = NULL;
11451147
#ifdef WOLFSSL_DEBUG_MEMORY
1146-
fprintf(stderr, "Looking for %lu bytes at %s:%d\n", (unsigned long) size, func,
1147-
line);
1148+
fprintf(stderr, "Looking for %lu bytes at %s:%d\n",
1149+
(unsigned long) size, func, line);
11481150
#endif
11491151
#ifdef WOLFSSL_STATIC_MEMORY_DEBUG_CALLBACK
11501152
if (DebugCb) {
@@ -1187,7 +1189,8 @@ void wolfSSL_Free(void *ptr, void* heap, int type)
11871189
#ifdef WOLFSSL_HEAP_TEST
11881190
if (heap == (void*)WOLFSSL_HEAP_TEST) {
11891191
#ifdef WOLFSSL_DEBUG_MEMORY
1190-
fprintf(stderr, "Free: %p at %s:%d\n", pt, func, line);
1192+
fprintf(stderr, "[HEAP %p] Free: %p at %s:%d\n", heap, pt, func,
1193+
line);
11911194
#endif
11921195
return free(ptr); /* native heap */
11931196
}
@@ -1205,16 +1208,17 @@ void wolfSSL_Free(void *ptr, void* heap, int type)
12051208
}
12061209
#endif
12071210
#ifndef WOLFSSL_NO_MALLOC
1211+
#ifdef WOLFSSL_DEBUG_MEMORY
1212+
fprintf(stderr, "[HEAP %p] Free: %p at %s:%d\n", heap, pt, func,
1213+
line);
1214+
#endif
12081215
#ifdef FREERTOS
12091216
vPortFree(ptr); /* native heap */
12101217
#elif defined(WOLFSSL_EMBOS)
12111218
OS_HEAP_free(ptr); /* native heap */
12121219
#else
12131220
free(ptr); /* native heap */
12141221
#endif
1215-
#ifdef WOLFSSL_DEBUG_MEMORY
1216-
fprintf(stderr, "Free: %p at %s:%d\n", ptr, func, line);
1217-
#endif
12181222
#else
12191223
WOLFSSL_MSG("Error trying to call free when turned off");
12201224
#endif /* WOLFSSL_NO_MALLOC */
@@ -1286,8 +1290,8 @@ void wolfSSL_Free(void *ptr, void* heap, int type)
12861290
#endif
12871291

12881292
#ifdef WOLFSSL_DEBUG_MEMORY
1289-
fprintf (stderr, "Free: %p -> %u at %s:%d\n", pt->buffer,
1290-
pt->szUsed, func, line);
1293+
fprintf(stderr, "[HEAP %p] Free: %p -> %u at %s:%d\n", heap,
1294+
pt->buffer, pt->szUsed, func, line);
12911295
#endif
12921296

12931297
#ifndef WOLFSSL_STATIC_MEMORY_LEAN

0 commit comments

Comments
 (0)