From 0184caac9de25258b23156016b3528e9878f1dae Mon Sep 17 00:00:00 2001 From: Nick Rivera Date: Thu, 9 Apr 2020 20:23:06 -0700 Subject: [PATCH] Provides an optional cleanup callback for async data. --- async.c | 5 +++++ async.h | 1 + 2 files changed, 6 insertions(+) diff --git a/async.c b/async.c index a966ed5..6990e86 100644 --- a/async.c +++ b/async.c @@ -109,6 +109,7 @@ static redisAsyncContext *redisAsyncInitialize(redisContext *c) { ac->err = 0; ac->errstr = NULL; ac->data = NULL; + ac->dataCleanup = NULL; ac->ev.data = NULL; ac->ev.addRead = NULL; @@ -299,6 +300,10 @@ static void __redisAsyncFree(redisAsyncContext *ac) { } } + if (ac->dataCleanup) { + ac->dataCleanup(ac->data); + } + /* Cleanup self */ redisFree(c); } diff --git a/async.h b/async.h index 4f6b3b7..781f1d1 100644 --- a/async.h +++ b/async.h @@ -70,6 +70,7 @@ typedef struct redisAsyncContext { /* Not used by hiredis */ void *data; + void (*dataCleanup)(void *privdata); /* Event library data and hooks */ struct {