Browse Source

rls: convert module to use DB_TABLE_VERSION_ERROR helper

- convert module to use DB_TABLE_VERSION_ERROR helper
- unify error handling (properly close database on errors, null db handle)
Henning Westerholt 6 năm trước cách đây
mục cha
commit
b1ad4001f4
1 tập tin đã thay đổi với 17 bổ sung8 xóa
  1. 17 8
      src/modules/rls/rls.c

+ 17 - 8
src/modules/rls/rls.c

@@ -483,21 +483,21 @@ static int mod_init(void)
 
 	/* verify table version */
 	if(db_check_table_version(&rls_dbf, rls_db, &rlsubs_table, W_TABLE_VERSION) < 0) {
-		LM_ERR("error during table version check.\n");
-		return -1;
+		DB_TABLE_VERSION_ERROR(rlsubs_table);
+		goto dberror;
 	}
 
 	/* verify table version */
 	if(db_check_table_version(&rlpres_dbf, rlpres_db, &rlpres_table, P_TABLE_VERSION) < 0) {
-		LM_ERR("error during table version check.\n");
-		return -1;
+		DB_TABLE_VERSION_ERROR(rlpres_table);
+		goto dberror;
 	}
 
 	/* verify table version */
 	if(db_check_table_version(&rls_xcap_dbf, rls_xcap_db, &rls_xcap_table, X_TABLE_VERSION) < 0)
 	{
-		LM_ERR("error during table version check.\n");
-		return -1;
+		DB_TABLE_VERSION_ERROR(rls_xcap_table);
+		goto dberror;
 	}
 
 	if (dbmode != RLS_DB_ONLY)
@@ -511,14 +511,14 @@ static int mod_init(void)
 		if(rls_table== NULL)
 		{
 			LM_ERR("while creating new hash table\n");
-			return -1;
+			goto dberror;
 		}
 		if(rls_reload_db_subs!=0)
 		{
 			if(rls_restore_db_subs()< 0)
 			{
 				LM_ERR("while restoring rl watchers table\n");
-				return -1;
+				goto dberror;
 			}
 		}
 	}
@@ -659,6 +659,15 @@ static int mod_init(void)
 	}
 
 	return 0;
+
+dberror:
+	rls_dbf.close(rls_db);
+	rls_db = NULL;
+	rlpres_dbf.close(rlpres_db);
+	rlpres_db = NULL;
+	rls_xcap_dbf.close(rls_xcap_db);
+	rls_xcap_db = NULL;
+	return -1;
 }
 
 /**