Ops, sorry, I send a wrong patch, that one creates an API for ndb_redis module.

The patch attached now is the correct one.

Regards,
Vicente.



On 05/02/2012 09:33 PM, Vicente Hernando wrote:
Hello,

looking at ndb_redis module source code I see replies are not freed when module is destroyed.

Also a reply is only freed when another one with same name is performed. This could cause problems if an user would ask for
a lot of different named replies.

IMHO freeing reply list when module is destroyed and creating a new redisc_free_reply function would solve this.


I attach a patch that compiles but not tested to show the idea.

If you agree I can perform the task, I suppose redisc_free_reply function should also be exported in cmd_export_t module structure.


This solution would be compatible with old ndb redis module configuration.



Regards,
Vicente.



_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

diff --git modules/ndb_redis/redis_client.c modules/ndb_redis/redis_client.c
index 234bb3a..6dc787d 100644
--- modules/ndb_redis/redis_client.c
+++ modules/ndb_redis/redis_client.c
@@ -102,13 +102,30 @@ err:
 	return -1;
 }
 
+
 /**
  *
  */
 int redisc_destroy(void)
 {
+	redisc_reply_t *rpl, *next_rpl;
+
 	redisc_server_t *rsrv=NULL;
 	redisc_server_t *rsrv1=NULL;
+
+	rpl=_redisc_rpl_list;
+	while(rpl != NULL)
+	{
+		next_rpl = rpl->next;
+		freeReplyObject(rpl->rplRedis);
+
+		if(rpl->rname.s != NULL)
+			pkg_free(rpl->rname.s);
+
+		pkg_free(rpl);
+		rpl = next_rpl;
+	}
+
 	if(_redisc_srv_list==NULL)
 		return -1;
 	rsrv=_redisc_srv_list;
@@ -121,6 +138,7 @@ int redisc_destroy(void)
 		free_params(rsrv1->attrs);
 		pkg_free(rsrv1);
 	}
+
 	return 0;
 }
 
@@ -344,3 +362,49 @@ redisc_reply_t *redisc_get_reply(str *name)
 	_redisc_rpl_list = rpl;
 	return rpl;
 }
+
+
+
+
+
+/**
+ *
+ */
+int redisc_free_reply(str *name)
+{
+	redisc_reply_t *rpl, *prev_rpl, *next_rpl;
+	unsigned int hid;
+
+	hid = get_hash1_raw(name->s, name->len);
+
+	prev_rpl = NULL;
+	rpl = _redisc_rpl_list;
+	while(rpl) {
+
+		if(rpl->hname==hid && rpl->rname.len==name->len
+		   && strncmp(rpl->rname.s, name->s, name->len)==0) {
+			next_rpl = rpl->next;
+			freeReplyObject(rpl->rplRedis);
+
+			if(rpl->rname.s != NULL)
+				pkg_free(rpl->rname.s);
+
+			pkg_free(rpl);
+
+			if(prev_rpl==NULL) {
+				/* We delete first element in the list. */
+				_redisc_rpl_list = next_rpl;
+			} else {
+				prev_rpl->next = next_rpl;
+			}
+
+			return 0;
+		}
+
+		prev_rpl = rpl;
+		rpl = rpl->next;
+	}
+
+	/* reply entry not found. */
+	return -1;
+}
_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to