Browse code

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 authored on 15/07/2010 12:02:46
Showing 2 changed files
... ...
@@ -1148,14 +1148,25 @@ error:
1148 1148
 }
1149 1149
 
1150 1150
 /**
1151
- *
1151
+ * destroy the content of pv_spec_t structure
1152 1152
  */
1153
-void pv_spec_free(pv_spec_t *spec)
1153
+void pv_spec_destroy(pv_spec_t *spec)
1154 1154
 {
1155 1155
 	if(spec==0) return;
1156
-	/* TODO: free name if it is PV */
1156
+	/* free name if it is PV */
1157
+	if(spec->pvp.pvn.nfree)
1158
+		spec->pvp.pvn.nfree((void*)(&spec->pvp.pvn));
1157 1159
 	if(spec->trans)
1158 1160
 		tr_free((trans_t*)spec->trans);
1161
+}
1162
+
1163
+/**
1164
+ * free the pv_spec_t structure
1165
+ */
1166
+void pv_spec_free(pv_spec_t *spec)
1167
+{
1168
+	if(spec==0) return;
1169
+	pv_spec_destroy(spec);
1159 1170
 	pkg_free(spec);
1160 1171
 }
1161 1172
 
... ...
@@ -84,6 +84,7 @@ enum _pv_type {
84 84
 typedef enum _pv_type pv_type_t;
85 85
 typedef int pv_flags_t;
86 86
 
87
+typedef void (*pv_name_free_f)(void*);
87 88
 
88 89
 typedef struct _pv_value
89 90
 {
... ...
@@ -95,6 +96,7 @@ typedef struct _pv_value
95 96
 typedef struct _pv_name
96 97
 {
97 98
 	int type;             /*!< type of name */
99
+	pv_name_free_f nfree; /*!< function to free name structure */
98 100
 	union {
99 101
 		struct {
100 102
 			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,
174 176
 int pv_printf(struct sip_msg* msg, pv_elem_p list, char *buf, int *len);
175 177
 int pv_elem_free_all(pv_elem_p log);
176 178
 void pv_value_destroy(pv_value_t *val);
179
+void pv_spec_destroy(pv_spec_t *spec);
177 180
 void pv_spec_free(pv_spec_t *spec);
178 181
 int pv_spec_dbg(pv_spec_p sp);
179 182
 int pv_get_spec_index(struct sip_msg* msg, pv_param_p ip, int *idx, int *flags);