X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=blobdiff_plain;f=src%2FmemoryDebug.c;h=d4e828f1aeb127ce84a8c00c41059e49a12518d2;hp=7d9e6ad0ceff0ded13ba59f338cc5143fab4fd00;hb=HEAD;hpb=d80ff9e6b878be4f29854f4fe99f59efeb5e6e10 diff --git a/src/memoryDebug.c b/src/memoryDebug.c index 7d9e6ad..d4e828f 100644 --- a/src/memoryDebug.c +++ b/src/memoryDebug.c @@ -1,4 +1,4 @@ -/* memoryDebug.c - NeonServ v5.5 +/* memoryDebug.c - NeonServ v5.6 * Copyright (C) 2011-2012 Philipp Kreil (pk910) * * This program is free software: you can redistribute it and/or modify @@ -17,6 +17,7 @@ #include "main.h" #include "memoryDebug.h" #include "memoryInfo.h" +#include "tools.h" #define FILE_NAME_LENGTH 256 #define OUTPUT_FILE "leak_info.txt" @@ -80,9 +81,10 @@ void xfree(void *mem_ref) { free(mem_ref); } - static void add_mem_info(void *mem_ref, unsigned int size, const char *file, unsigned int line) { - SYNCHRONIZE(synchronized); + #ifdef HAVE_THREADS + pthread_mutex_lock(&synchronized); + #endif struct MemoryLeak *mem_leak_info = malloc(sizeof(*mem_leak_info)); own_allocated_memleaks++; mem_leak_info->mem_info.address = mem_ref; @@ -91,11 +93,15 @@ static void add_mem_info(void *mem_ref, unsigned int size, const char *file, uns mem_leak_info->mem_info.line = line; mem_leak_info->next = ptr_start; ptr_start = mem_leak_info; - DESYNCHRONIZE(synchronized); + #ifdef HAVE_THREADS + pthread_mutex_unlock(&synchronized); + #endif } static void remove_mem_info(void *mem_ref) { - SYNCHRONIZE(synchronized); + #ifdef HAVE_THREADS + pthread_mutex_lock(&synchronized); + #endif struct MemoryLeak *leak_info, *next, *prev = NULL; for(leak_info = ptr_start; leak_info; leak_info = next) { next = leak_info->next; @@ -110,7 +116,9 @@ static void remove_mem_info(void *mem_ref) { } else prev = leak_info; } - DESYNCHRONIZE(synchronized); + #ifdef HAVE_THREADS + pthread_mutex_unlock(&synchronized); + #endif } void initMemoryDebug() { @@ -118,7 +126,9 @@ void initMemoryDebug() { } struct memoryInfoFiles *getMemoryInfoFiles() { - SYNCHRONIZE(synchronized); + #ifdef HAVE_THREADS + pthread_mutex_lock(&synchronized); + #endif struct MemoryLeak *leak_info; struct memoryInfoFiles *list = NULL, *element; for(leak_info = ptr_start; leak_info != NULL; leak_info = leak_info->next) { @@ -144,7 +154,9 @@ struct memoryInfoFiles *getMemoryInfoFiles() { element->allocated = own_allocated_memleaks * sizeof(struct MemoryLeak); element->next = list; list = element; - DESYNCHRONIZE(synchronized); + #ifdef HAVE_THREADS + pthread_mutex_unlock(&synchronized); + #endif return list; } @@ -158,7 +170,9 @@ void freeMemoryInfoFiles(struct memoryInfoFiles *files) { } struct memoryInfoLines *getMemoryInfoLines(const char *filename) { - SYNCHRONIZE(synchronized); + #ifdef HAVE_THREADS + pthread_mutex_lock(&synchronized); + #endif struct MemoryLeak *leak_info; struct memoryInfoLines *list = NULL, *element; for(leak_info = ptr_start; leak_info != NULL; leak_info = leak_info->next) { @@ -186,7 +200,9 @@ struct memoryInfoLines *getMemoryInfoLines(const char *filename) { element->next = list; list = element; } - DESYNCHRONIZE(synchronized); + #ifdef HAVE_THREADS + pthread_mutex_unlock(&synchronized); + #endif return list; }