浏览代码

topos: Safety check for database storage

Carsten Bock 8 年之前
父节点
当前提交
05b31ddbfa
共有 1 个文件被更改,包括 20 次插入0 次删除
  1. 20 0
      src/modules/topos/tps_storage.c

+ 20 - 0
src/modules/topos/tps_storage.c

@@ -448,6 +448,11 @@ int tps_db_insert_dialog(tps_data_t *td)
 	db_val_t db_vals[TPS_NR_KEYS];
 	int nr_keys;
 
+	if (_tps_db_handle == NULL) {
+		LM_ERR("No database handle - misconfiguration?\n");
+		goto error;
+	}
+
 	memset(db_keys, 0, TPS_NR_KEYS*sizeof(db_key_t));
 	memset(db_vals, 0, TPS_NR_KEYS*sizeof(db_val_t));
 	nr_keys = 0;
@@ -583,6 +588,11 @@ int tps_db_clean_dialogs(void)
 	db_op_t  db_ops[2];
 	int nr_keys;
 
+	if (_tps_db_handle == NULL) {
+		LM_ERR("No database handle - misconfiguration?\n");
+		return -1;
+	}
+
 	nr_keys = 0;
 
 	LM_DBG("cleaning expired dialog records\n");
@@ -629,6 +639,11 @@ int tps_db_insert_branch(tps_data_t *td)
 	db_val_t db_vals[TPS_NR_KEYS];
 	int nr_keys;
 
+	if (_tps_db_handle == NULL) {
+		LM_ERR("No database handle - misconfiguration?\n");
+		goto error;
+	}
+
 	memset(db_keys, 0, TPS_NR_KEYS*sizeof(db_key_t));
 	memset(db_vals, 0, TPS_NR_KEYS*sizeof(db_val_t));
 	nr_keys = 0;
@@ -730,6 +745,11 @@ int tps_db_clean_branches(void)
 	db_op_t  db_ops[2];
 	int nr_keys;
 
+	if (_tps_db_handle == NULL) {
+		LM_ERR("No database handle - misconfiguration?\n");
+		return -1;
+	}
+
 	nr_keys = 0;
 
 	LM_DBG("cleaning expired branch records\n");