[sr-dev] git:master: app_lua: use pv spec cache
Daniel-Constantin Mierla
miconda at gmail.com
Tue Sep 6 21:49:44 CEST 2011
Module: sip-router
Branch: master
Commit: 08a4bbcecfb878fc520f4a2bab182bda1526ce62
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=08a4bbcecfb878fc520f4a2bab182bda1526ce62
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: Tue Sep 6 21:47:45 2011 +0200
app_lua: use pv spec cache
- avoid memory leaks when working with PVs that have dynamic name
---
modules/app_lua/app_lua_sr.c | 48 +++++++++++++++++++++++++++++++----------
1 files changed, 36 insertions(+), 12 deletions(-)
diff --git a/modules/app_lua/app_lua_sr.c b/modules/app_lua/app_lua_sr.c
index c5f5bf8..1271ba2 100644
--- a/modules/app_lua/app_lua_sr.c
+++ b/modules/app_lua/app_lua_sr.c
@@ -873,9 +873,10 @@ static const luaL_reg _sr_hdr_Map [] = {
static int lua_sr_pv_get (lua_State *L)
{
str pvn;
- pv_spec_t pvs;
+ pv_spec_t *pvs;
pv_value_t val;
sr_lua_env_t *env_L;
+ int pl;
env_L = sr_lua_env_get();
@@ -885,13 +886,20 @@ static int lua_sr_pv_get (lua_State *L)
pvn.len = strlen(pvn.s);
LM_DBG("pv get: %s\n", pvn.s);
- if(pv_parse_spec(&pvn, &pvs)<0)
+ pl = pv_locate_name(&pvn);
+ if(pl != pvn.len)
{
- LM_ERR("unable to parse pv [%s]\n", pvn.s);
+ LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
+ return 0;
+ }
+ pvs = pv_cache_get(&pvn);
+ if(pvs==NULL)
+ {
+ LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
return 0;
}
memset(&val, 0, sizeof(pv_value_t));
- if(pv_get_spec_value(env_L->msg, &pvs, &val) != 0)
+ if(pv_get_spec_value(env_L->msg, pvs, &val) != 0)
{
LM_ERR("unable to get pv value for [%s]\n", pvn.s);
return 0;
@@ -915,9 +923,10 @@ static int lua_sr_pv_get (lua_State *L)
static int lua_sr_pv_seti (lua_State *L)
{
str pvn;
- pv_spec_t pvs;
+ pv_spec_t *pvs;
pv_value_t val;
sr_lua_env_t *env_L;
+ int pl;
env_L = sr_lua_env_get();
@@ -941,12 +950,19 @@ static int lua_sr_pv_seti (lua_State *L)
pvn.len = strlen(pvn.s);
LM_DBG("pv set: %s\n", pvn.s);
- if(pv_parse_spec(&pvn, &pvs)<0)
+ pl = pv_locate_name(&pvn);
+ if(pl != pvn.len)
{
- LM_ERR("unable to parse pv [%s]\n", pvn.s);
+ LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
return 0;
}
- if(pv_set_spec_value(env_L->msg, &pvs, 0, &val)<0)
+ pvs = pv_cache_get(&pvn);
+ if(pvs==NULL)
+ {
+ LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
+ return 0;
+ }
+ if(pv_set_spec_value(env_L->msg, pvs, 0, &val)<0)
{
LM_ERR("unable to set pv [%s]\n", pvn.s);
return 0;
@@ -961,9 +977,10 @@ static int lua_sr_pv_seti (lua_State *L)
static int lua_sr_pv_sets (lua_State *L)
{
str pvn;
- pv_spec_t pvs;
+ pv_spec_t *pvs;
pv_value_t val;
sr_lua_env_t *env_L;
+ int pl;
env_L = sr_lua_env_get();
@@ -983,12 +1000,19 @@ static int lua_sr_pv_sets (lua_State *L)
pvn.len = strlen(pvn.s);
LM_DBG("pv set: %s\n", pvn.s);
- if(pv_parse_spec(&pvn, &pvs)<0)
+ pl = pv_locate_name(&pvn);
+ if(pl != pvn.len)
{
- LM_ERR("unable to parse pv [%s]\n", pvn.s);
+ LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
return 0;
}
- if(pv_set_spec_value(env_L->msg, &pvs, 0, &val)<0)
+ pvs = pv_cache_get(&pvn);
+ if(pvs==NULL)
+ {
+ LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
+ return 0;
+ }
+ if(pv_set_spec_value(env_L->msg, pvs, 0, &val)<0)
{
LM_ERR("unable to set pv [%s]\n", pvn.s);
return 0;
More information about the sr-dev
mailing list