-
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
Program crashes due to Segmentation fault or double free using AsyncCommand (PUBLISH..) #1258
Comments
Hi, The version of Hiredis you're using, v0.14, is quite out of date compared to the current stable version, which is v1.2.0. I'd need a bit more detail about your code to be of any help. Can you provide a minimally reproducable example (a complete code listing I can compile to reproduce the bug)? If not a full call-stack could help. It's important to note that Hiredis isn't thread-safe. So, if you're sharing a redisContext across multiple threads without proper synchronization you will encounter undefined behavior. I'm happy to take a look if you can provide a compilable example |
Thanks @michael-grunder for your quick response. I am using mutex to access the context across different threads. We are using the old version as it is the only available version from the Ubuntu 22.04 distribution. Is the latest version(v1.2.0) compatible with libevent available across various linux distributions? |
It should be compatible with any of the event libraries we have adapters for. I just checked and it wasn't until ubuntu 24.04 that they updated from v0.14 to v1.1.0. |
Based on your information, I have integrated our software with hiredis - 1.1.0.
|
Hey, I can see that there is a memory corruption but there's no reason to believe hiredis is causing the corruption. My money would be on improperly sharing of the It is useful to run your program under I'm curious why you're using threads at all. Sometimes it's worthwhile to use an async event library and multiple threads but often you just need one thread with multiple callbacks. You mentioned using a mutex to control access to the I recently wrote a little quick-and-dirty toy program that uses async hiredis to bounce messages back and forth between two messaging channels. I'm not sure if this is at all similar to what you're doing but you can see I don't use threads. I use two |
I'm going to close this issue since it's unlikely a bug in hiredis. If you can provide a reproducer that I can run though, I'm happy to take a deeper look. |
System (Ubuntu22.04) - using libhiredis-dev with libevent-dev provided within the distribution (i.e hiredis -0.14 & libevent-2.1)
Here is the code snippet:
callback context
redis_publish_reply()
{
free (str1);
free (str2);
}
thread1:
{
...
malloc (str1);
malloc (str2);
redisAsyncCommand (ctx, redis_publish_reply, privdata, "PUBLISH %s %s", str1, str2);
}
where str1 and str2 are allocated in thread1 and freed in the callback context.
The text was updated successfully, but these errors were encountered: