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
8d702189
Commit
8d702189
authored
Dec 10, 2014
by
Matt Stancliff
Browse files
Remove malloc failure checks
We trust zmalloc to kill the whole process on memory failure
parent
e0d94a7b
Changes
1
Show whitespace changes
Inline
Side-by-side
src/quicklist.c
View file @
8d702189
...
@@ -67,14 +67,11 @@ static const size_t optimization_level[] = { 4096, 8192, 16384, 32768, 65536 };
...
@@ -67,14 +67,11 @@ static const size_t optimization_level[] = { 4096, 8192, 16384, 32768, 65536 };
} while (0)
} while (0)
/* Create a new quicklist.
/* Create a new quicklist.
* Free with quicklistRelease().
* Free with quicklistRelease(). */
*
* On error, NULL is returned. Otherwise the pointer to the new quicklist. */
quicklist *quicklistCreate(void) {
quicklist *quicklistCreate(void) {
struct quicklist *quicklist;
struct quicklist *quicklist;
if
((
quicklist
=
zmalloc
(
sizeof
(
*
quicklist
)))
==
NULL
)
quicklist = zmalloc(sizeof(*quicklist));
return
NULL
;
quicklist->head = quicklist->tail = NULL;
quicklist->head = quicklist->tail = NULL;
quicklist->len = 0;
quicklist->len = 0;
quicklist->count = 0;
quicklist->count = 0;
...
@@ -83,8 +80,7 @@ quicklist *quicklistCreate(void) {
...
@@ -83,8 +80,7 @@ quicklist *quicklistCreate(void) {
static quicklistNode *quicklistCreateNode(void) {
static quicklistNode *quicklistCreateNode(void) {
quicklistNode *node;
quicklistNode *node;
if
((
node
=
zmalloc
(
sizeof
(
*
node
)))
==
NULL
)
node = zmalloc(sizeof(*node));
return
NULL
;
node->zl = NULL;
node->zl = NULL;
node->count = 0;
node->count = 0;
node->sz = 0;
node->sz = 0;
...
@@ -537,14 +533,7 @@ static quicklistNode *_quicklistSplitNode(quicklistNode *node, int offset,
...
@@ -537,14 +533,7 @@ static quicklistNode *_quicklistSplitNode(quicklistNode *node, int offset,
size_t zl_sz = ziplistBlobLen(node->zl);
size_t zl_sz = ziplistBlobLen(node->zl);
quicklistNode *new_node = quicklistCreateNode();
quicklistNode *new_node = quicklistCreateNode();
if
(
!
new_node
)
return
NULL
;
new_node->zl = zmalloc(zl_sz);
new_node->zl = zmalloc(zl_sz);
if
(
!
new_node
->
zl
)
{
zfree
(
new_node
);
return
NULL
;
}
/* Copy original ziplist so we can split it */
/* Copy original ziplist so we can split it */
memcpy(new_node->zl, node->zl, zl_sz);
memcpy(new_node->zl, node->zl, zl_sz);
...
@@ -782,8 +771,7 @@ int quicklistCompare(unsigned char *p1, unsigned char *p2, int p2_len) {
...
@@ -782,8 +771,7 @@ int quicklistCompare(unsigned char *p1, unsigned char *p2, int p2_len) {
quicklistIter *quicklistGetIterator(const quicklist *quicklist, int direction) {
quicklistIter *quicklistGetIterator(const quicklist *quicklist, int direction) {
quicklistIter *iter;
quicklistIter *iter;
if
((
iter
=
zmalloc
(
sizeof
(
*
iter
)))
==
NULL
)
iter = zmalloc(sizeof(*iter));
return
NULL
;
if (direction == AL_START_HEAD) {
if (direction == AL_START_HEAD) {
iter->current = quicklist->head;
iter->current = quicklist->head;
...
@@ -904,7 +892,7 @@ int quicklistNext(quicklistIter *iter, quicklistEntry *entry) {
...
@@ -904,7 +892,7 @@ int quicklistNext(quicklistIter *iter, quicklistEntry *entry) {
}
}
}
}
/* Duplicate the quicklist.
On out of memory NULL is returned.
/* Duplicate the quicklist.
* On success a copy of the original quicklist is returned.
* On success a copy of the original quicklist is returned.
*
*
* The original quicklist both on success or error is never modified.
* The original quicklist both on success or error is never modified.
...
@@ -912,20 +900,15 @@ int quicklistNext(quicklistIter *iter, quicklistEntry *entry) {
...
@@ -912,20 +900,15 @@ int quicklistNext(quicklistIter *iter, quicklistEntry *entry) {
* Returns newly allocated quicklist. */
* Returns newly allocated quicklist. */
quicklist *quicklistDup(quicklist *orig) {
quicklist *quicklistDup(quicklist *orig) {
quicklist *copy;
quicklist *copy;
int
failure
=
0
;
if
((
copy
=
quicklistCreate
())
==
NULL
)
copy = quicklistCreate();
return
NULL
;
for (quicklistNode *current = orig->head; current;
for (quicklistNode *current = orig->head; current;
current = current->next) {
current = current->next) {
quicklistNode *node = quicklistCreateNode();
quicklistNode *node = quicklistCreateNode();
size_t ziplen = ziplistBlobLen(current->zl);
size_t ziplen = ziplistBlobLen(current->zl);
if
((
node
->
zl
=
zmalloc
(
ziplen
))
==
NULL
)
{
node->zl = zmalloc(ziplen);
failure
=
1
;
break
;
}
memcpy(node->zl, current->zl, ziplen);
memcpy(node->zl, current->zl, ziplen);
node->count = current->count;
node->count = current->count;
...
@@ -936,12 +919,6 @@ quicklist *quicklistDup(quicklist *orig) {
...
@@ -936,12 +919,6 @@ quicklist *quicklistDup(quicklist *orig) {
}
}
/* copy->count must equal orig->count here */
/* copy->count must equal orig->count here */
if
(
failure
)
{
quicklistRelease
(
copy
);
return
NULL
;
}
return copy;
return copy;
}
}
...
@@ -1100,8 +1077,7 @@ int quicklistPopCustom(quicklist *quicklist, int where, unsigned char **data,
...
@@ -1100,8 +1077,7 @@ int quicklistPopCustom(quicklist *quicklist, int where, unsigned char **data,
static void *_quicklistSaver(unsigned char *data, unsigned int sz) {
static void *_quicklistSaver(unsigned char *data, unsigned int sz) {
unsigned char *vstr;
unsigned char *vstr;
if (data) {
if (data) {
if
((
vstr
=
zmalloc
(
sz
))
==
NULL
)
vstr = zmalloc(sz);
return
0
;
memcpy(data, vstr, sz);
memcpy(data, vstr, sz);
return vstr;
return vstr;
}
}
...
...
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