X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/fc96409f9193a7fda1dd509d16769272453f36c0..64ef44d56835d068592e10eb588a8daad2168a08:/src/ae.c diff --git a/src/ae.c b/src/ae.c index 6ddccdf7..4099b125 100644 --- a/src/ae.c +++ b/src/ae.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "ae.h" #include "zmalloc.h" @@ -56,32 +57,30 @@ aeEventLoop *aeCreateEventLoop(int setsize) { aeEventLoop *eventLoop; int i; - if ((eventLoop = zmalloc(sizeof(*eventLoop))) == NULL) return NULL; - eventLoop->events = NULL; - eventLoop->fired = NULL; + if ((eventLoop = zmalloc(sizeof(*eventLoop))) == NULL) goto err; eventLoop->events = zmalloc(sizeof(aeFileEvent)*setsize); eventLoop->fired = zmalloc(sizeof(aeFiredEvent)*setsize); - if (eventLoop->events == NULL || eventLoop->fired == NULL) { - zfree(eventLoop->events); - zfree(eventLoop->fired); - zfree(eventLoop); - return NULL; - } + if (eventLoop->events == NULL || eventLoop->fired == NULL) goto err; eventLoop->setsize = setsize; eventLoop->timeEventHead = NULL; eventLoop->timeEventNextId = 0; eventLoop->stop = 0; eventLoop->maxfd = -1; eventLoop->beforesleep = NULL; - if (aeApiCreate(eventLoop) == -1) { - zfree(eventLoop); - return NULL; - } + if (aeApiCreate(eventLoop) == -1) goto err; /* Events with mask == AE_NONE are not set. So let's initialize the * vector with it. */ for (i = 0; i < setsize; i++) eventLoop->events[i].mask = AE_NONE; return eventLoop; + +err: + if (eventLoop) { + zfree(eventLoop->events); + zfree(eventLoop->fired); + zfree(eventLoop); + } + return NULL; } void aeDeleteEventLoop(aeEventLoop *eventLoop) {