34 #if defined(HEAP_UNIT_TESTS) 35 char* Broker_recordFFDC(
char* symptoms);
45 #if !defined(NO_HEAP_TRACKING) 51 #if defined(_WIN32) || defined(_WIN64) 74 #if defined(HEAP_STACK) 80 static const char *
errmsg =
"Memory allocation error";
100 static int multsize = 4*
sizeof(int);
102 if (size % multsize != 0)
103 size += multsize - (size % multsize);
120 return (a > b) ? -1 : (a == b) ? 0 : 1;
162 size_t filenamelen = strlen(file)+1;
181 memset(s->
file, 0,
sizeof(filenamelen));
183 space += filenamelen;
184 strcpy(s->
file, file);
185 #if defined(HEAP_STACK) 186 #define STACK_LEN 300 187 if ((s->stack =
malloc(STACK_LEN)) == NULL)
194 memset(s->stack, 0,
sizeof(filenamelen));
210 Log(
TRACE_MAX, -1,
"Allocating %d bytes in heap at file %s line %d ptr %p\n", (
int)size, file, line, s->
ptr);
227 static const char *msg =
"Invalid %s eyecatcher %d in heap item at file %s line %d";
252 Log(
LOG_ERROR, 13,
"Failed to remove heap item at file %s line %d", file, line);
256 Log(
TRACE_MAX, -1,
"Freeing %d bytes in heap at file %s line %d, heap use now %d bytes\n",
277 void myfree(
char* file,
int line,
void* p)
288 Log(
LOG_ERROR, -1,
"Call of free(NULL) in %s,%d",file,line);
320 void *
myrealloc(
char* file,
int line,
void* p,
size_t size)
328 Log(
LOG_ERROR, 13,
"Failed to reallocate heap item at file %s line %d", file, line);
332 size_t filenamelen = strlen(file)+1;
348 space -= strlen(s->
file);
350 space += filenamelen;
351 strcpy(s->
file, file);
375 return (e == NULL) ? NULL : e->content;
385 Node* current = NULL;
388 Log(log_level, -1,
"Heap scan start, total %d bytes", (
int)state.
current_size);
392 Log(log_level, -1,
"Heap element size %d, line %d, file %s, ptr %p", (
int)s->
size, s->
line, s->
file, s->
ptr);
393 Log(log_level, -1,
" Content %.*s", (10 > current->size) ? (
int)s->
size : 10, (
char*)(((
eyecatcherType*)s->
ptr) + 1));
394 #if defined(HEAP_STACK) 395 Log(log_level, -1,
" Stack:\n%s", s->stack);
398 Log(log_level, -1,
"Heap scan end");
422 Log(
LOG_ERROR, -1,
"Some memory not freed at shutdown, possible memory leak");
446 size_t len = str ? strlen(str) + 1 : 0;
448 if (fwrite(&(str),
sizeof(
char*), 1, file) != 1)
450 else if (fwrite(&(len),
sizeof(
int), 1 ,file) != 1)
452 else if (len > 0 && fwrite(str, len, 1, file) != 1)
465 Node* current = NULL;
471 if (fwrite(&(s->
ptr),
sizeof(s->
ptr), 1, file) != 1)
473 else if (fwrite(&(current->size),
sizeof(current->size), 1, file) != 1)
475 else if (fwrite(s->
ptr, current->size, 1, file) != 1)
484 #if defined(HEAP_UNIT_TESTS) 491 char* Broker_recordFFDC(
char* symptoms)
493 printf(
"recordFFDC");
497 #define malloc(x) mymalloc(__FILE__, __LINE__, x) 498 #define realloc(a, b) myrealloc(__FILE__, __LINE__, a, b) 499 #define free(x) myfree(__FILE__, __LINE__, x) 501 int main(
int argc,
char *argv[])
516 printf(
"freeing h\n");
519 printf(
"Finishing\n");
enum MQTTPropertyCodes value
void * TreeAdd(Tree *aTree, void *content, size_t size)
static pthread_mutex_t heap_mutex_store
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
static mutex_type heap_mutex
int HeapDumpString(FILE *file, char *str)
void * Heap_findItem(void *p)
void * TreeRemoveKey(Tree *aTree, void *key)
int Thread_lock_mutex(mutex_type mutex)
void * myrealloc(char *file, int line, void *p, size_t size)
void Heap_unlink(char *file, int line, void *p)
void * mymalloc(char *file, int line, size_t size)
char * StackTrace_get(thread_id_type threadid, char *buf, int bufsize)
static int Internal_heap_unlink(char *file, int line, void *p)
void * TreeRemoveNodeIndex(Tree *aTree, Node *curnode, int index)
static size_t Heap_roundup(size_t size)
void myfree(char *file, int line, void *p)
unsigned int heap_tracking
void TreeInitializeNoMalloc(Tree *aTree, int(*compare)(void *, void *, int))
static const char * errmsg
Node * TreeNextElement(Tree *aTree, Node *curnode)
int Thread_unlock_mutex(mutex_type mutex)
void Log(enum LOG_LEVELS log_level, int msgno, const char *format,...)
heap_info * Heap_get_info(void)
Node * TreeFind(Tree *aTree, void *key)
void Heap_terminate(void)
int Heap_initialize(void)
static void checkEyecatchers(char *file, int line, void *p, size_t size)
thread_id_type Thread_getid(void)
static int ptrCompare(void *a, void *b, int value)
static eyecatcherType eyecatcher
int main(int argc, char **argv)
static void HeapScan(enum LOG_LEVELS log_level)