From 8521cde570f574006ee36a2d3e0ed1b2f6953d2f Mon Sep 17 00:00:00 2001
From: Dvir Volk <dvirsky@gmail.com>
Date: Wed, 30 Nov 2016 11:49:49 +0200
Subject: [PATCH] fix memory corruption on RM_FreeCallReply

---
 src/module.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/module.c b/src/module.c
index 07f88eff..08b653e1 100644
--- a/src/module.c
+++ b/src/module.c
@@ -2286,8 +2286,10 @@ void RM_FreeCallReply_Rec(RedisModuleCallReply *reply, int freenested){
  * to have the first level function to return on nested replies, but only
  * if called by the module API. */
 void RM_FreeCallReply(RedisModuleCallReply *reply) {
+
+    RedisModuleCtx *ctx = reply->ctx;
     RM_FreeCallReply_Rec(reply,0);
-    autoMemoryFreed(reply->ctx,REDISMODULE_AM_REPLY,reply);
+    autoMemoryFreed(ctx,REDISMODULE_AM_REPLY,reply);
 }
 
 /* Return the reply type. */