summaryrefslogtreecommitdiff
path: root/src/zmalloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/zmalloc.c')
-rw-r--r--src/zmalloc.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/zmalloc.c b/src/zmalloc.c
index 308774d86..2482f512b 100644
--- a/src/zmalloc.c
+++ b/src/zmalloc.c
@@ -164,7 +164,7 @@ void *zrealloc(void *ptr, size_t size) {
if (!newptr) zmalloc_oom_handler(size);
*((size_t*)newptr) = size;
- update_zmalloc_stat_free(oldsize);
+ update_zmalloc_stat_free(oldsize+PREFIX_SIZE);
update_zmalloc_stat_alloc(size+PREFIX_SIZE);
return (char*)newptr+PREFIX_SIZE;
#endif
@@ -438,4 +438,20 @@ size_t zmalloc_get_memory_size(void) {
#endif
}
-
+#ifdef REDIS_TEST
+#define UNUSED(x) ((void)(x))
+int zmalloc_test(int argc, char **argv) {
+ void *ptr;
+
+ UNUSED(argc);
+ UNUSED(argv);
+ printf("Initial used memory: %zu\n", zmalloc_used_memory());
+ ptr = zmalloc(123);
+ printf("Allocated 123 bytes; used: %zu\n", zmalloc_used_memory());
+ ptr = zrealloc(ptr, 456);
+ printf("Reallocated to 456 bytes; used: %zu\n", zmalloc_used_memory());
+ zfree(ptr);
+ printf("Freed pointer; used: %zu\n", zmalloc_used_memory());
+ return 0;
+}
+#endif