aboutsummaryrefslogtreecommitdiff
path: root/src/memdebug.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/memdebug.h')
-rw-r--r--src/memdebug.h30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/memdebug.h b/src/memdebug.h
index d219397..358203a 100644
--- a/src/memdebug.h
+++ b/src/memdebug.h
@@ -15,7 +15,7 @@
* - MEMDEBUG_OUTPUT_DIR - set the directory for the log,
* by default it is the current directory (automatically
* enables the MEMDEBUG_OUTPUT_LOG
- */
+ */
void *__memdebug_malloc(size_t size, char *file, int line);
void *__memdebug_calloc(size_t nmemb, size_t size, char *file, int line);
@@ -48,7 +48,7 @@ void __memdebug_free(void *ptr, char *file, int line);
#define MEMDEBUG_OUTPUT_DIR "."
#endif
-#ifdef MEMDEBUG_OUTPUT_LOG
+#ifdef MEMDEBUG_OUTPUT_LOG
#define MEMDEBUG_OUTPUT_FMT "memdebug-%lu.log"
#endif
@@ -103,7 +103,7 @@ void *__memdebug_malloc(size_t size, char *file, int line)
#endif
MEMDEBUG_LOG_FUNC(malloc, addr, file, line);
-
+
MEMDEBUG_LOG("size: %zu, ret: %p", size, addr);
MEMDEBUG_LOG("\n");
@@ -120,9 +120,9 @@ void *__memdebug_realloc(void *ptr, size_t size, char *file, int line)
ptr, size + MEMDEBUG_OUT_OF_BOUNDS_EXTRA_SIZE);
MEMDEBUG_OUT_OF_BOUNDS_CHECK(addr, size);
#endif
-
+
MEMDEBUG_LOG_FUNC(realloc, addr, file, line);
-
+
MEMDEBUG_LOG("ptr: %p, size: %zu, ret: %p", ptr, size, addr);
MEMDEBUG_LOG("\n");
@@ -140,9 +140,9 @@ void *__memdebug_calloc(size_t nmemb, size_t size, char *file, int line)
MEMDEBUG_OUT_OF_BOUNDS_CHECK(addr, nmemb * size);
memset(addr, 0, nmemb * size);
#endif
-
+
MEMDEBUG_LOG_FUNC(calloc, addr, file, line);
-
+
MEMDEBUG_LOG("nmemb: %zu, size: %zu, ret: %p", nmemb, size, addr);
MEMDEBUG_LOG("\n");
@@ -151,9 +151,9 @@ void *__memdebug_calloc(size_t nmemb, size_t size, char *file, int line)
}
void __memdebug_free(void *ptr, char *file, int line)
-{
+{
MEMDEBUG_LOG_FUNC(free, (void *)1, file, line);
-
+
MEMDEBUG_LOG("ptr: %p", ptr);
#ifdef MEMDEBUG_OUT_OF_BOUNDS
@@ -164,11 +164,11 @@ void __memdebug_free(void *ptr, char *file, int line)
MEMDEBUG_LOG(", ");
MEMDEBUG_LOG("out-of-bounds-check: ");
-
+
if(suffix == (memdebug_suffix)MEMDEBUG_MAGIC_SUFFIX)
MEMDEBUG_LOG("SUCCESS");
else MEMDEBUG_LOG("FAILED");
-
+
ptr -= sizeof(size_t);
}
#endif
@@ -193,15 +193,15 @@ int main(int argc, char **argv)
(void)argc;
(void)argv;
#endif
-
+
#ifdef MEMDEBUG_OUTPUT_LOG
size_t filename_sz = 64 + sizeof(MEMDEBUG_OUTPUT_DIR) + sizeof(MEMDEBUG_OUTPUT_FMT);
char *filename = malloc(filename_sz);
if(!filename) return -ENOMEM;
-
+
memset(filename, 0, filename_sz);
snprintf(filename, filename_sz, MEMDEBUG_OUTPUT_DIR"/"MEMDEBUG_OUTPUT_FMT, time(NULL));
-
+
_memdebug_fp = fopen(filename, "w");
if(!_memdebug_fp) {
perror(filename);
@@ -210,7 +210,7 @@ int main(int argc, char **argv)
}
int ret = CALL_MAIN;
-
+
fclose(_memdebug_fp);
free(filename);
return ret;