|
@@ -131,6 +131,7 @@ static int db_write_cdr( struct dlg_cell* dialog,
|
|
|
struct sip_msg* message)
|
|
|
{
|
|
|
int m = 0;
|
|
|
+ int n = 0;
|
|
|
int i;
|
|
|
db_func_t *df=NULL;
|
|
|
db1_con_t *dh=NULL;
|
|
@@ -163,11 +164,12 @@ static int db_write_cdr( struct dlg_cell* dialog,
|
|
|
/* get extra values */
|
|
|
if (message)
|
|
|
{
|
|
|
- m += extra2strar( cdr_extra,
|
|
|
+ n += extra2strar( cdr_extra,
|
|
|
message,
|
|
|
cdr_value_array + m,
|
|
|
cdr_int_array + m,
|
|
|
cdr_type_array + m);
|
|
|
+ m += n;
|
|
|
} else if (cdr_expired_dlg_enable){
|
|
|
LM_WARN( "fallback to dlg_only search because of message doesn't exist.\n");
|
|
|
m += extra2strar_dlg_only( cdr_extra,
|
|
@@ -187,27 +189,34 @@ static int db_write_cdr( struct dlg_cell* dialog,
|
|
|
|
|
|
if (df->use_table(dh, &acc_cdrs_table /*table*/) < 0) {
|
|
|
LM_ERR("error in use_table\n");
|
|
|
- return -1;
|
|
|
+ goto error;
|
|
|
}
|
|
|
|
|
|
if(acc_db_insert_mode==1 && df->insert_delayed!=NULL) {
|
|
|
if (df->insert_delayed(dh, db_cdr_keys, db_cdr_vals, m) < 0) {
|
|
|
LM_ERR("failed to insert delayed into database\n");
|
|
|
- return -1;
|
|
|
+ goto error;
|
|
|
}
|
|
|
} else if(acc_db_insert_mode==2 && df->insert_async!=NULL) {
|
|
|
if (df->insert_async(dh, db_cdr_keys, db_cdr_vals, m) < 0) {
|
|
|
LM_ERR("failed to insert async into database\n");
|
|
|
- return -1;
|
|
|
+ goto error;
|
|
|
}
|
|
|
} else {
|
|
|
if (df->insert(dh, db_cdr_keys, db_cdr_vals, m) < 0) {
|
|
|
LM_ERR("failed to insert into database\n");
|
|
|
- return -1;
|
|
|
+ goto error;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /* Free memory allocated by acc_extra.c/extra2strar */
|
|
|
+ free_strar_mem( &(cdr_type_array[m-n]), &(cdr_value_array[m-n]), n, m);
|
|
|
return 0;
|
|
|
+
|
|
|
+error:
|
|
|
+ /* Free memory allocated by acc_extra.c/extra2strar */
|
|
|
+ free_strar_mem( &(cdr_type_array[m-n]), &(cdr_value_array[m-n]), n, m);
|
|
|
+ return -1;
|
|
|
}
|
|
|
#endif
|
|
|
|
|
@@ -221,6 +230,7 @@ static int log_write_cdr( struct dlg_cell* dialog,
|
|
|
2;// -2 because of the string ending '\n\0'
|
|
|
char* message_position = NULL;
|
|
|
int message_index = 0;
|
|
|
+ int extra_index = 0;
|
|
|
int counter = 0;
|
|
|
|
|
|
if(cdr_log_enable==0)
|
|
@@ -235,7 +245,7 @@ static int log_write_cdr( struct dlg_cell* dialog,
|
|
|
/* get extra values */
|
|
|
if (message)
|
|
|
{
|
|
|
- message_index += extra2strar( cdr_extra,
|
|
|
+ extra_index += extra2strar( cdr_extra,
|
|
|
message,
|
|
|
cdr_value_array + message_index,
|
|
|
cdr_int_array + message_index,
|
|
@@ -249,7 +259,7 @@ static int log_write_cdr( struct dlg_cell* dialog,
|
|
|
cdr_type_array + message_index,
|
|
|
&dlgb);
|
|
|
}
|
|
|
-
|
|
|
+ message_index += extra_index;
|
|
|
|
|
|
for( counter = 0, message_position = cdr_message;
|
|
|
counter < message_index ;
|
|
@@ -296,6 +306,9 @@ static int log_write_cdr( struct dlg_cell* dialog,
|
|
|
|
|
|
LM_GEN2( cdr_facility, log_level, "%s", cdr_message);
|
|
|
|
|
|
+ /* free memory allocated by extra2strar, nothing is done in case no extra strings were found by extra2strar */
|
|
|
+ free_strar_mem( &(cdr_type_array[message_index-extra_index]), &(cdr_value_array[message_index-extra_index]),
|
|
|
+ extra_index, message_index);
|
|
|
return 0;
|
|
|
}
|
|
|
|