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
8d196eba
Commit
8d196eba
authored
Apr 30, 2009
by
antirez
Browse files
zmalloc fix, return NULL or real malloc failure
parent
71aee3e9
Changes
1
Hide whitespace changes
Inline
Side-by-side
zmalloc.c
View file @
8d196eba
...
@@ -36,6 +36,7 @@ static size_t used_memory = 0;
...
@@ -36,6 +36,7 @@ static size_t used_memory = 0;
void
*
zmalloc
(
size_t
size
)
{
void
*
zmalloc
(
size_t
size
)
{
void
*
ptr
=
malloc
(
size
+
sizeof
(
size_t
));
void
*
ptr
=
malloc
(
size
+
sizeof
(
size_t
));
if
(
!
ptr
)
return
NULL
;
*
((
size_t
*
)
ptr
)
=
size
;
*
((
size_t
*
)
ptr
)
=
size
;
used_memory
+=
size
+
sizeof
(
size_t
);
used_memory
+=
size
+
sizeof
(
size_t
);
return
(
char
*
)
ptr
+
sizeof
(
size_t
);
return
(
char
*
)
ptr
+
sizeof
(
size_t
);
...
...
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