diff options
author | Jay Sorg <jay.sorg@gmail.com> | 2019-10-22 22:00:23 +0300 |
---|---|---|
committer | Jay Sorg <jay.sorg@gmail.com> | 2019-10-22 22:00:23 +0300 |
commit | 94997b7dfda4d94313dbf47e7e10cbb4299b8f0a (patch) | |
tree | c0c47206ba3a537d3f6b2c60736ce2402e17ae39 | |
parent | 8e06e5bc78b3b519b77ff2ffda896ce4aba2beca (diff) |
add some more memory logging
-rw-r--r-- | libfreerdp-utils/memory.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/libfreerdp-utils/memory.c b/libfreerdp-utils/memory.c index 72a8dae..a14bfc0 100644 --- a/libfreerdp-utils/memory.c +++ b/libfreerdp-utils/memory.c @@ -25,6 +25,7 @@ #include <freerdp/utils/memory.h> +#define MEMORY_MAX_ALLOC (64 * 1024 * 1024) /** * Allocate memory. * @param size @@ -36,12 +37,12 @@ void* xmalloc(size_t size) if (size < 1) { - printf("xmalloc: adjusting xmalloc bytes\n"); + printf("xmalloc: adjusting xmalloc bytes %d\n", (int) size); size = 1; } - if (size > 16 * 1024 * 1024) + if (size > MEMORY_MAX_ALLOC) { - printf("xmalloc: bad size\n"); + printf("xmalloc: bad size %d\n", (int) size); return NULL; } mem = malloc(size); @@ -63,16 +64,22 @@ void* xzalloc(size_t size) void* mem; if (size < 1) + { + printf("xzalloc: adjusting xzalloc bytes %d\n", (int) size); size = 1; + } + if (size > MEMORY_MAX_ALLOC) + { + printf("xzalloc: bad size %d\n", (int) size); + return NULL; + } mem = calloc(1, size); - if (mem == NULL) { perror("xzalloc"); printf("xzalloc: failed to allocate memory of size: %d\n", (int) size); } - return mem; } @@ -87,19 +94,26 @@ void* xrealloc(void* ptr, size_t size) void* mem; if (size < 1) + { + printf("xrealloc: adjusting xrealloc bytes %d\n", (int) size); size = 1; - + } + if (size > MEMORY_MAX_ALLOC) + { + printf("xrealloc: bad size %d\n", (int) size); + return NULL; + } if (ptr == NULL) { printf("xrealloc: null pointer given\n"); return NULL; } - mem = realloc(ptr, size); - if (mem == NULL) + { perror("xrealloc"); - + printf("xrealloc: failed to allocate memory of size: %d\n", (int) size); + } return mem; } |