Browse Source

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
Daniel-Constantin Mierla 15 years ago
parent
commit
2b2f495455
2 changed files with 17 additions and 3 deletions
  1. 14 3
      pvapi.c
  2. 3 0
      pvar.h

+ 14 - 3
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);
 }
 

+ 3 - 0
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);