-
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
Change in redisReply memory ownership for redisAsyncCommand #79
Comments
+1 on this. Just caused me a major headache, since the readme says that I have to take care of freeing replies. I'm not sure what the best option would be here, since sometimes I don't want to take care of freeing objects myself. But other times I want to keep a copy for later use. |
Thanks for submitting this issue. I also would expect this behavior to be different right now (how viewpoints change over time...). I'm slowly rewriting parts of hiredis (see the For the usage described by @janoberst I'm a proponent of only free'ing the reply if there is no callback to handle it. |
Cool to hear that you're rewriting parts of hiredis.. I'm just using a version that has the freeObject line commented out and I'm taking care of freeing the reply struct myself. That has been working pretty good so far. My use-case is this:
Therefore I need to hold on to the redisReply struct even after my proxy callback function has finished. On the other hand, I have multiple "simple" calls where I don't need the redisReply function once the callback has finished. I'd say 90% of the time I don't need to hold on to the reply. I will implement this on my branch in a bit: Add another kind of callback function that sets a flag in the redisCallback struct. Upon calling the callback, hiredis checks if the Let me know if it would help at all if I attached my changes here or opened a pull request... |
Callbacks definitely need to be able to retain the reply. Given that the reply is deep object and non-trivial to duplicate, I think it was a mistake to ever prevent a callback retaining it. That said, I don't see any advantage of adding a flag either. I have no problem with all callbacks required to free the reply themselves. Only if no callback is supplied should it automatically free. It's the principle of least surprise. This is serious enough that it shouldn't wait for ng, imho. |
I'm going to close this very old issue but after v1.0.0 we can look at making this more flexible. One option is to use refcounts for the |
Commit 3ce8d5b changed the behavior of async callbacks by always freeing memory after the callback instead of leaving it to the callback. This change may not have been noticed since it looks like the samples using the async API weren't even freeing memory properly before the change.
Either this was intended, in which case the readme should be updated to reflect the change in behavior, e.g.:
If this was not intended, the fix is probably more substantial since the commit that made the relevant change suggests the pub/sub code uses this code path and probably relies on it to free the replies. However, I don't haven't used the pub/sub code at all or looked at its implementation, so I am not certain about that.
The text was updated successfully, but these errors were encountered: