Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to replace allocator and handle OOM everywhere. #800

Merged
merged 22 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
be5f5ef
Pluggable memory allocation and proper OOM handling
michael-grunder Apr 28, 2020
ee652b6
Merge branch 'master' into pluggable-allocation
michael-grunder May 4, 2020
8fe3dd7
Fix a potential memory leak in ssl.c
michael-grunder May 4, 2020
a32192b
Update missed allocations to our wrapper define
michael-grunder May 5, 2020
3e8835e
Fix redisReaderTask elements type
michael-grunder May 7, 2020
8d59446
More robuse async OOM handling
michael-grunder May 7, 2020
58e72a4
Fix two compilation errors
michael-grunder May 7, 2020
cbb7fe6
Fix potential memory leak
michael-grunder May 11, 2020
3e10335
Allow for a configurable max multi-bulk elements setting
michael-grunder May 12, 2020
4fe636a
Allow library users to specify allocator
michael-grunder May 12, 2020
7257a49
Add extern C if we detect C++
michael-grunder May 12, 2020
19d4577
Fix windows compilation
michael-grunder May 12, 2020
8a7d6a8
Disable pluggable allocation for Windows
michael-grunder May 12, 2020
85f8746
Attempt cleaner Win32 logic
michael-grunder May 13, 2020
fdb182e
Further simplify Win32 logic
michael-grunder May 13, 2020
9efea93
Re-enable allocator injection in Windows
michael-grunder May 14, 2020
9487d18
Minor refactor and name changes
michael-grunder May 15, 2020
2843337
Fix typo
michael-grunder May 19, 2020
4e8fd61
Merge remote-tracking branch 'upstream/master' into pluggable-allocation
michael-grunder May 19, 2020
324cadf
Remove piecemeal allocator override
michael-grunder May 22, 2020
e5a1879
Fix memory leak introduced merging upstream/master
michael-grunder May 22, 2020
06318f2
Merge branch 'master' into pluggable-allocation
michael-grunder May 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update missed allocations to our wrapper define
  • Loading branch information
michael-grunder committed May 5, 2020
commit a32192bf6fd1bae62497476116f266e51a66b461
2 changes: 1 addition & 1 deletion adapters/ae.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static void redisAeCleanup(void *privdata) {
redisAeEvents *e = (redisAeEvents*)privdata;
redisAeDelRead(privdata);
redisAeDelWrite(privdata);
free(e);
hi_free(e);
}

static int redisAeAttach(aeEventLoop *loop, redisAsyncContext *ac) {
Expand Down
2 changes: 1 addition & 1 deletion adapters/ivykis.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static void redisIvykisCleanup(void *privdata) {
redisIvykisEvents *e = (redisIvykisEvents*)privdata;

iv_fd_unregister(&e->fd);
free(e);
hi_free(e);
}

static int redisIvykisAttach(redisAsyncContext *ac) {
Expand Down
2 changes: 1 addition & 1 deletion adapters/libev.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static void redisLibevCleanup(void *privdata) {
redisLibevDelRead(privdata);
redisLibevDelWrite(privdata);
redisLibevStopTimer(privdata);
free(e);
hi_free(e);
}

static void redisLibevTimeout(EV_P_ ev_timer *timer, int revents) {
Expand Down
2 changes: 1 addition & 1 deletion adapters/libevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ typedef struct redisLibeventEvents {
} redisLibeventEvents;

static void redisLibeventDestroy(redisLibeventEvents *e) {
free(e);
hi_free(e);
}

static void redisLibeventHandler(int fd, short event, void *arg) {
Expand Down
2 changes: 1 addition & 1 deletion adapters/libuv.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static void redisLibuvDelWrite(void *privdata) {
static void on_close(uv_handle_t* handle) {
redisLibuvEvents* p = (redisLibuvEvents*)handle->data;

free(p);
hi_free(p);
}


Expand Down
2 changes: 1 addition & 1 deletion adapters/macosx.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static int freeRedisRunLoop(RedisRunLoop* redisRunLoop) {
CFSocketInvalidate(redisRunLoop->socketRef);
CFRelease(redisRunLoop->socketRef);
}
free(redisRunLoop);
hi_free(redisRunLoop);
}
return REDIS_ERR;
}
Expand Down
2 changes: 1 addition & 1 deletion dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static int dictExpand(dict *ht, unsigned long size) {
_dictInit(&n, ht->type, ht->privdata);
n.size = realsize;
n.sizemask = realsize-1;
n.table = calloc(realsize,sizeof(dictEntry*));
n.table = hi_calloc(realsize,sizeof(dictEntry*));
if (n.table == NULL)
return DICT_ERR;

Expand Down
6 changes: 3 additions & 3 deletions hiredis.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static void *createDoubleObject(const redisReadTask *task, double value, char *s
return NULL;

r->dval = value;
r->str = malloc(len+1);
r->str = hi_malloc(len+1);
if (r->str == NULL) {
freeReplyObject(r);
return NULL;
Expand Down Expand Up @@ -470,7 +470,7 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) {
totlen += 1+countDigits(argc)+2;

/* Build the command at protocol level */
cmd = malloc(totlen+1);
cmd = hi_malloc(totlen+1);
if (cmd == NULL) goto memory_err;

pos = sprintf(cmd,"*%d\r\n",argc);
Expand Down Expand Up @@ -618,7 +618,7 @@ int redisFormatCommandArgv(char **target, int argc, const char **argv, const siz
}

/* Build the command at protocol level */
cmd = malloc(totlen+1);
cmd = hi_malloc(totlen+1);
if (cmd == NULL)
return -1;

Expand Down
10 changes: 5 additions & 5 deletions read.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,15 @@ static int redisReaderGrow(redisReader *r) {

/* Grow our stack size */
newlen = r->tasks + REDIS_READER_STACK_SIZE;
aux = realloc(r->task, sizeof(*r->task) * newlen);
aux = hi_realloc(r->task, sizeof(*r->task) * newlen);
if (aux == NULL)
goto oom;

r->task = aux;

/* Allocate new tasks */
for (; r->tasks < newlen; r->tasks++) {
r->task[r->tasks] = calloc(1, sizeof(**r->task));
r->task[r->tasks] = hi_calloc(1, sizeof(**r->task));
if (r->task[r->tasks] == NULL)
goto oom;
}
Expand Down Expand Up @@ -594,7 +594,7 @@ redisReader *redisReaderCreateWithFunctions(redisReplyObjectFunctions *fn) {
if (r->buf == NULL)
goto oom;

r->task = calloc(REDIS_READER_STACK_SIZE, sizeof(*r->task));
r->task = hi_calloc(REDIS_READER_STACK_SIZE, sizeof(*r->task));
if (r->task == NULL)
goto oom;

Expand Down Expand Up @@ -623,11 +623,11 @@ void redisReaderFree(redisReader *r) {

/* We know r->task[i] is allocatd if i < r->tasks */
for (int i = 0; i < r->tasks; i++) {
free(r->task[i]);
hi_free(r->task[i]);
}

if (r->task)
free(r->task);
hi_free(r->task);

sdsfree(r->buf);
hi_free(r);
Expand Down
2 changes: 1 addition & 1 deletion ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ static void redisSSLFreeContext(void *privdata){
SSL_CTX_free(rsc->ssl_ctx);
rsc->ssl_ctx = NULL;
}
free(rsc);
hi_free(rsc);
}

static int redisSSLRead(redisContext *c, char *buf, size_t bufcap) {
Expand Down