-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Safe allocation wrappers #754
Conversation
Just quoting the last parts of the conversation in a merged PR from @michael-grunder
Thanks... and I think the changes in this PR would work for me. 👍 |
Would be great to get some more eyes on this. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we using asprintf and friends anywhere?
No, but |
Merged, thanks everyone! |
@@ -57,7 +58,7 @@ static unsigned int callbackHash(const void *key) { | |||
|
|||
static void *callbackValDup(void *privdata, const void *src) { | |||
((void) privdata); | |||
redisCallback *dup = malloc(sizeof(*dup)); | |||
redisCallback *dup = hi_malloc(sizeof(*dup)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can still result in a SEGFAULT,
If hi_malloc returns NULL -> next call to memcpy will SEGFAULT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just waking up here but how can hi_malloc return NULL if HIREDIS_OOM_HANDLER
is called? (eg. _exit
?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lamby yeah, I forgot to redo the comment, talked about it already with @michael-grunder
either way personally I'm against doing abort()
if we can handle it, for example when doing callback-allocation, we can return error instead of abort, remember that this is a 3rd-party library for most users, and crashing someone's application due to internal errors is not the way to do things IMHO
Adds allocation wrappers that invokes a defined OOM handler.
My goal was the smallest surface area of changes possible. Once we merge this it might be prudent to replace every
malloc
/free
call with our wrappers.