Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
9ce63869
Unverified
Commit
9ce63869
authored
Oct 01, 2018
by
Salvatore Sanfilippo
Committed by
GitHub
Oct 01, 2018
Browse files
Merge pull request #5398 from bmerry/fix-zrealloc-accounting
Fix incorrect memory usage accounting in zrealloc
parents
cd2ee8b1
8fd1031b
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/server.c
View file @
9ce63869
...
...
@@ -4019,6 +4019,8 @@ int main(int argc, char **argv) {
return
endianconvTest
(
argc
,
argv
);
}
else
if
(
!
strcasecmp
(
argv
[
2
],
"crc64"
))
{
return
crc64Test
(
argc
,
argv
);
}
else
if
(
!
strcasecmp
(
argv
[
2
],
"zmalloc"
))
{
return
zmalloc_test
(
argc
,
argv
);
}
return
-
1
;
/* test not found */
...
...
src/zmalloc.c
View file @
9ce63869
...
...
@@ -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
src/zmalloc.h
View file @
9ce63869
...
...
@@ -103,4 +103,8 @@ size_t zmalloc_usable(void *ptr);
#define zmalloc_usable(p) zmalloc_size(p)
#endif
#ifdef REDIS_TEST
int
zmalloc_test
(
int
argc
,
char
**
argv
);
#endif
#endif
/* __ZMALLOC_H */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment