diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-03-15 19:21:35 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-03-15 19:21:35 +0100 |
| commit | 9dae91f1993c563cf97a87b84836dc3b6306714a (patch) | |
| tree | b0b8ec366fc4d3c64615a1a47222d9f278870d57 /mem | |
| parent | eeed387a65d9dbdafddffab8e6f8b507262ffaf5 (diff) | |
remove mem
Diffstat (limited to 'mem')
| -rw-r--r-- | mem/LICENSE.txt | 21 | ||||
| -rw-r--r-- | mem/mem.cpp | 85 | ||||
| -rw-r--r-- | mem/mem.h | 11 |
3 files changed, 0 insertions, 117 deletions
diff --git a/mem/LICENSE.txt b/mem/LICENSE.txt deleted file mode 100644 index af4ad2e..0000000 --- a/mem/LICENSE.txt +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License - -Copyright (c) 2015-2018 Bibhas Bhattacharya - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/mem/mem.cpp b/mem/mem.cpp deleted file mode 100644 index 43f5a89..0000000 --- a/mem/mem.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS - -#include <stdlib.h> -#include <stdio.h> -#ifndef _WIN32 -#include <unistd.h> -#endif -#pragma warning(disable : 4996) -void *debug_malloc(size_t size, const char* file, int line) { - void *p = malloc(size); - - if (p == NULL) { - return NULL; - } - - char buff[256]; - - sprintf(buff, "bin/debug/mem/%p.mem", p); - - FILE *f = fopen(buff, "w"); - if (!f) return p; - fprintf(f, "File: %s\nLine: %d\nSize: %zu bytes\n", file, line, size); - fclose(f); - - return p; -} - -void *debug_calloc(size_t count, size_t size, const char* file, int line) { - void *p = calloc(count, size); - - if (p == NULL) { - return NULL; - } - - char buff[256]; - - sprintf(buff, "bin/debug/mem/%p.mem", p); - - FILE *f = fopen(buff, "w"); - if (!f) return p; - - fprintf(f, "File: %s\nLine: %d\nSize: %zu bytes\n", file, line, - count * size); - fclose(f); - - return p; -} - -void *debug_realloc(void *ptr, size_t size, const char* file, int line) { - void *p = realloc(ptr, size); - - if (p == NULL) { - return NULL; - } - - char buff[256]; - //Delete the old pointer record - sprintf(buff, "bin/debug/mem/%p.mem", ptr); - if (ptr != NULL && unlink(buff) < 0) { - printf("Double free: %p File: %s Line: %d\n", ptr, file, line); - } - - //Create the new pointer record - sprintf(buff, "bin/debug/mem/%p.mem", p); - - FILE *f = fopen(buff, "w"); - if (!f) return p; - - fprintf(f, "File: %s\nLine: %d\nSize: %zu bytes\n", file, line, size); - fclose(f); - - return p; -} - -void debug_free(void *p, const char* file, int line) { - char buff[256]; - - sprintf(buff, "bin/debug/mem/%p.mem", p); - if (p != NULL && unlink(buff) < 0) { - printf("Double free: %p File: %s Line: %d\n", p, file, line); - } - - free(p); -} - diff --git a/mem/mem.h b/mem/mem.h deleted file mode 100644 index cc6597b..0000000 --- a/mem/mem.h +++ /dev/null @@ -1,11 +0,0 @@ -void *debug_malloc(size_t size, const char* file, int line); -void *debug_calloc(size_t count, size_t size, const char* file, int line); -void *debug_realloc(void *ptr, size_t size, const char* file, int line); -void debug_free(void *p, const char* file, int line); - -#ifdef TS_DEBUG -#define malloc(s) debug_malloc(s, __FILE__, __LINE__) -#define calloc(c, s) debug_calloc(c, s, __FILE__, __LINE__) -#define realloc(p, s) debug_realloc(p, s, __FILE__, __LINE__) -#define free(p) debug_free(p, __FILE__, __LINE__) -#endif |
