Skip to content

Commit 8d70218

Browse files
committed
Remove malloc failure checks
We trust zmalloc to kill the whole process on memory failure
1 parent e0d94a7 commit 8d70218

File tree

1 file changed

+8
-32
lines changed

1 file changed

+8
-32
lines changed

src/quicklist.c

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,11 @@ static const size_t optimization_level[] = { 4096, 8192, 16384, 32768, 65536 };
6767
} while (0)
6868

6969
/* Create a new quicklist.
70-
* Free with quicklistRelease().
71-
*
72-
* On error, NULL is returned. Otherwise the pointer to the new quicklist. */
70+
* Free with quicklistRelease(). */
7371
quicklist *quicklistCreate(void) {
7472
struct quicklist *quicklist;
7573

76-
if ((quicklist = zmalloc(sizeof(*quicklist))) == NULL)
77-
return NULL;
74+
quicklist = zmalloc(sizeof(*quicklist));
7875
quicklist->head = quicklist->tail = NULL;
7976
quicklist->len = 0;
8077
quicklist->count = 0;
@@ -83,8 +80,7 @@ quicklist *quicklistCreate(void) {
8380

8481
static quicklistNode *quicklistCreateNode(void) {
8582
quicklistNode *node;
86-
if ((node = zmalloc(sizeof(*node))) == NULL)
87-
return NULL;
83+
node = zmalloc(sizeof(*node));
8884
node->zl = NULL;
8985
node->count = 0;
9086
node->sz = 0;
@@ -537,14 +533,7 @@ static quicklistNode *_quicklistSplitNode(quicklistNode *node, int offset,
537533
size_t zl_sz = ziplistBlobLen(node->zl);
538534

539535
quicklistNode *new_node = quicklistCreateNode();
540-
if (!new_node)
541-
return NULL;
542-
543536
new_node->zl = zmalloc(zl_sz);
544-
if (!new_node->zl) {
545-
zfree(new_node);
546-
return NULL;
547-
}
548537

549538
/* Copy original ziplist so we can split it */
550539
memcpy(new_node->zl, node->zl, zl_sz);
@@ -782,8 +771,7 @@ int quicklistCompare(unsigned char *p1, unsigned char *p2, int p2_len) {
782771
quicklistIter *quicklistGetIterator(const quicklist *quicklist, int direction) {
783772
quicklistIter *iter;
784773

785-
if ((iter = zmalloc(sizeof(*iter))) == NULL)
786-
return NULL;
774+
iter = zmalloc(sizeof(*iter));
787775

788776
if (direction == AL_START_HEAD) {
789777
iter->current = quicklist->head;
@@ -904,28 +892,23 @@ int quicklistNext(quicklistIter *iter, quicklistEntry *entry) {
904892
}
905893
}
906894

907-
/* Duplicate the quicklist. On out of memory NULL is returned.
895+
/* Duplicate the quicklist.
908896
* On success a copy of the original quicklist is returned.
909897
*
910898
* The original quicklist both on success or error is never modified.
911899
*
912900
* Returns newly allocated quicklist. */
913901
quicklist *quicklistDup(quicklist *orig) {
914902
quicklist *copy;
915-
int failure = 0;
916903

917-
if ((copy = quicklistCreate()) == NULL)
918-
return NULL;
904+
copy = quicklistCreate();
919905

920906
for (quicklistNode *current = orig->head; current;
921907
current = current->next) {
922908
quicklistNode *node = quicklistCreateNode();
923909

924910
size_t ziplen = ziplistBlobLen(current->zl);
925-
if ((node->zl = zmalloc(ziplen)) == NULL) {
926-
failure = 1;
927-
break;
928-
}
911+
node->zl = zmalloc(ziplen);
929912
memcpy(node->zl, current->zl, ziplen);
930913

931914
node->count = current->count;
@@ -936,12 +919,6 @@ quicklist *quicklistDup(quicklist *orig) {
936919
}
937920

938921
/* copy->count must equal orig->count here */
939-
940-
if (failure) {
941-
quicklistRelease(copy);
942-
return NULL;
943-
}
944-
945922
return copy;
946923
}
947924

@@ -1100,8 +1077,7 @@ int quicklistPopCustom(quicklist *quicklist, int where, unsigned char **data,
11001077
static void *_quicklistSaver(unsigned char *data, unsigned int sz) {
11011078
unsigned char *vstr;
11021079
if (data) {
1103-
if ((vstr = zmalloc(sz)) == NULL)
1104-
return 0;
1080+
vstr = zmalloc(sz);
11051081
memcpy(data, vstr, sz);
11061082
return vstr;
11071083
}

0 commit comments

Comments
 (0)