[sr-dev] git:master: core: added pv name free function
Daniel-Constantin Mierla
miconda at gmail.com
Thu Jul 15 14:08:10 CEST 2010
Module: sip-router
Branch: master
Commit: 2b2f4954554edaa7797a3e29da056b80393ec5dd
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=2b2f4954554edaa7797a3e29da056b80393ec5dd
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: Thu Jul 15 14:02:46 2010 +0200
core: added pv name free function
- some PVs have dynamic name, therefore parsing them at runtime result in
memory leak
- the new attribute allow to free such kind of names
- not the case so far with stable versions but this can happen when using
such PVs with app_lua
---
pvapi.c | 17 ++++++++++++++---
pvar.h | 3 +++
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/pvapi.c b/pvapi.c
index bbd4b87..baeddab 100644
--- a/pvapi.c
+++ b/pvapi.c
@@ -1148,14 +1148,25 @@ error:
}
/**
- *
+ * destroy the content of pv_spec_t structure
*/
-void pv_spec_free(pv_spec_t *spec)
+void pv_spec_destroy(pv_spec_t *spec)
{
if(spec==0) return;
- /* TODO: free name if it is PV */
+ /* free name if it is PV */
+ if(spec->pvp.pvn.nfree)
+ spec->pvp.pvn.nfree((void*)(&spec->pvp.pvn));
if(spec->trans)
tr_free((trans_t*)spec->trans);
+}
+
+/**
+ * free the pv_spec_t structure
+ */
+void pv_spec_free(pv_spec_t *spec)
+{
+ if(spec==0) return;
+ pv_spec_destroy(spec);
pkg_free(spec);
}
diff --git a/pvar.h b/pvar.h
index 58fe38b..e7701f2 100644
--- a/pvar.h
+++ b/pvar.h
@@ -84,6 +84,7 @@ enum _pv_type {
typedef enum _pv_type pv_type_t;
typedef int pv_flags_t;
+typedef void (*pv_name_free_f)(void*);
typedef struct _pv_value
{
@@ -95,6 +96,7 @@ typedef struct _pv_value
typedef struct _pv_name
{
int type; /*!< type of name */
+ pv_name_free_f nfree; /*!< function to free name structure */
union {
struct {
int type; /*!< type of int_str name - compatibility with AVPs */
@@ -174,6 +176,7 @@ int pv_set_spec_value(struct sip_msg* msg, pv_spec_p sp, int op,
int pv_printf(struct sip_msg* msg, pv_elem_p list, char *buf, int *len);
int pv_elem_free_all(pv_elem_p log);
void pv_value_destroy(pv_value_t *val);
+void pv_spec_destroy(pv_spec_t *spec);
void pv_spec_free(pv_spec_t *spec);
int pv_spec_dbg(pv_spec_p sp);
int pv_get_spec_index(struct sip_msg* msg, pv_param_p ip, int *idx, int *flags);
More information about the sr-dev
mailing list