mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 17:10:50 +00:00
Merge pull request #5398 from bmerry/fix-zrealloc-accounting
Fix incorrect memory usage accounting in zrealloc
This commit is contained in:
commit
9ce638695c
@ -4019,6 +4019,8 @@ int main(int argc, char **argv) {
|
|||||||
return endianconvTest(argc, argv);
|
return endianconvTest(argc, argv);
|
||||||
} else if (!strcasecmp(argv[2], "crc64")) {
|
} else if (!strcasecmp(argv[2], "crc64")) {
|
||||||
return crc64Test(argc, argv);
|
return crc64Test(argc, argv);
|
||||||
|
} else if (!strcasecmp(argv[2], "zmalloc")) {
|
||||||
|
return zmalloc_test(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1; /* test not found */
|
return -1; /* test not found */
|
||||||
|
@ -164,7 +164,7 @@ void *zrealloc(void *ptr, size_t size) {
|
|||||||
if (!newptr) zmalloc_oom_handler(size);
|
if (!newptr) zmalloc_oom_handler(size);
|
||||||
|
|
||||||
*((size_t*)newptr) = size;
|
*((size_t*)newptr) = size;
|
||||||
update_zmalloc_stat_free(oldsize);
|
update_zmalloc_stat_free(oldsize+PREFIX_SIZE);
|
||||||
update_zmalloc_stat_alloc(size+PREFIX_SIZE);
|
update_zmalloc_stat_alloc(size+PREFIX_SIZE);
|
||||||
return (char*)newptr+PREFIX_SIZE;
|
return (char*)newptr+PREFIX_SIZE;
|
||||||
#endif
|
#endif
|
||||||
@ -438,4 +438,20 @@ size_t zmalloc_get_memory_size(void) {
|
|||||||
#endif
|
#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
|
||||||
|
@ -103,4 +103,8 @@ size_t zmalloc_usable(void *ptr);
|
|||||||
#define zmalloc_usable(p) zmalloc_size(p)
|
#define zmalloc_usable(p) zmalloc_size(p)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef REDIS_TEST
|
||||||
|
int zmalloc_test(int argc, char **argv);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __ZMALLOC_H */
|
#endif /* __ZMALLOC_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user