Skip to content

Commit

Permalink
Added REDIS_NO_AUTO_FREE_REPLIES flag (redis#962)
Browse files Browse the repository at this point in the history
When set hiredis will not automatically free replies in an async context, and the replies must be freed instead by the user.

Co-authored-by: Michael Grunder <michael.grunder@gmail.com>
  • Loading branch information
MeirShpilraien and michael-grunder committed Jul 11, 2021
1 parent 5850a8e commit f5f31ff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion async.c
Expand Up @@ -569,7 +569,9 @@ void redisProcessCallbacks(redisAsyncContext *ac) {

if (cb.fn != NULL) {
__redisRunCallback(ac,&cb,reply);
c->reader->fn->freeObject(reply);
if (!(c->flags & REDIS_NO_AUTO_FREE_REPLIES)){
c->reader->fn->freeObject(reply);
}

/* Proceed with free'ing when redisAsyncFree() was called. */
if (c->flags & REDIS_FREEING) {
Expand Down
3 changes: 3 additions & 0 deletions hiredis.c
Expand Up @@ -804,6 +804,9 @@ redisContext *redisConnectWithOptions(const redisOptions *options) {
if (options->options & REDIS_OPT_NOAUTOFREE) {
c->flags |= REDIS_NO_AUTO_FREE;
}
if (options->options & REDIS_OPT_NOAUTOFREEREPLIES) {
c->flags |= REDIS_NO_AUTO_FREE_REPLIES;
}

/* Set any user supplied RESP3 PUSH handler or use freeReplyObject
* as a default unless specifically flagged that we don't want one. */
Expand Down
8 changes: 8 additions & 0 deletions hiredis.h
Expand Up @@ -86,6 +86,9 @@ typedef long long ssize_t;
*/
#define REDIS_NO_AUTO_FREE 0x200

/* Flag that indicates the user does not want replies to be automatically freed */
#define REDIS_NO_AUTO_FREE_REPLIES 0x400

#define REDIS_KEEPALIVE_INTERVAL 15 /* seconds */

/* number of times we retry to connect in the case of EADDRNOTAVAIL and
Expand Down Expand Up @@ -153,6 +156,11 @@ struct redisSsl;
/* Don't automatically intercept and free RESP3 PUSH replies. */
#define REDIS_OPT_NO_PUSH_AUTOFREE 0x08

/**
* Don't automatically free replies
*/
#define REDIS_OPT_NOAUTOFREEREPLIES 0x10

/* In Unix systems a file descriptor is a regular signed int, with -1
* representing an invalid descriptor. In Windows it is a SOCKET
* (32- or 64-bit unsigned integer depending on the architecture), where
Expand Down

0 comments on commit f5f31ff

Please sign in to comment.