[Asterisk-code-review] cdr_mysql: Clear column list before scanning table (asterisk[18])

Dennis asteriskteam at digium.com
Wed Jul 29 05:01:55 CDT 2020


Dennis has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/14700 )


Change subject: cdr_mysql: Clear column list before scanning table
......................................................................

cdr_mysql: Clear column list before scanning table

When Asterisk re-connects to MySQL, table column names are
appended to the existing column list. This results in execution
errors due to duplicate column names listed in the INSERT query.

This change also fixes two warnings:

When MYSQL_VERSION_ID < 50013, "my_bool_true" becomes
unused and compiler will complain about it.

"entry" in my_unload_module is always unused.

ASTERISK-29007 #close

Change-Id: I899aa94ff34f48d8c7d73bc7f707dcd6f6a4ee36
---
M addons/cdr_mysql.c
1 file changed, 14 insertions(+), 7 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/00/14700/1

diff --git a/addons/cdr_mysql.c b/addons/cdr_mysql.c
index c05b86a..723f74d 100644
--- a/addons/cdr_mysql.c
+++ b/addons/cdr_mysql.c
@@ -108,6 +108,14 @@
 
 static MYSQL mysql = { { NULL }, };
 
+static void my_clear_columns(void)
+{
+	struct column *entry;
+	while ((entry = AST_RWLIST_REMOVE_HEAD(&columns, list))) {
+		ast_free(entry);
+	}
+}
+
 static char *handle_cli_cdr_mysql_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	switch (cmd) {
@@ -173,12 +181,13 @@
 {
 	struct ast_str *sql1 = ast_str_thread_get(&sql1_buf, 1024), *sql2 = ast_str_thread_get(&sql2_buf, 1024);
 	int retries = 5;
+#if MYSQL_VERSION_ID >= 50013
 #ifdef HAVE_MYSQLCLIENT_BOOL
 	bool my_bool_true = 1;
 #elif HAVE_MYSQLCLIENT_MY_BOOL
 	my_bool my_bool_true = 1;
-#endif
-
+#endif /* HAVE_MYSQLCLIENT_MY_BOOL */
+#endif /* MYSQL_VERSION_ID */
 	if (!sql1 || !sql2) {
 		ast_log(LOG_ERROR, "Memory error\n");
 		return -1;
@@ -382,8 +391,6 @@
 
 static int my_unload_module(int reload)
 {
-	struct column *entry;
-
 	if (!reload) {
 		if (ast_cdr_unregister(name)) {
 			/* If we can't unregister the backend, we can't unload the module */
@@ -404,9 +411,7 @@
 	if (!reload) {
 		AST_RWLIST_WRLOCK(&columns);
 	}
-	while ((entry = AST_RWLIST_REMOVE_HEAD(&columns, list))) {
-		ast_free(entry);
-	}
+	my_clear_columns();
 	if (!reload) {
 		AST_RWLIST_UNLOCK(&columns);
 	}
@@ -531,6 +536,8 @@
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
+	my_clear_columns();
+
 	while ((row = mysql_fetch_row(result))) {
 		struct column *entry;
 		char *cdrvar = "", *staticvalue = "";

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/14700
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: I899aa94ff34f48d8c7d73bc7f707dcd6f6a4ee36
Gerrit-Change-Number: 14700
Gerrit-PatchSet: 1
Gerrit-Owner: Dennis <dennis.buteyn at xorcom.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200729/ad07c133/attachment.html>


More information about the asterisk-code-review mailing list