]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Memory leaks in realtime_multi_xxx() when database access returns error.
authorRichard Mudgett <rmudgett@digium.com>
Mon, 22 Aug 2011 18:14:59 +0000 (18:14 +0000)
committerRichard Mudgett <rmudgett@digium.com>
Mon, 22 Aug 2011 18:14:59 +0000 (18:14 +0000)
* Fix realtime_multi_pgsql() configuration memory leak when the database
access returns an error.

* Fix realtime_multi_odbc() configuration category use after free when the
database access returns an error.

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@332816 65c4cc65-6c06-0410-ace0-fbb531ad65f3

res/res_config_odbc.c
res/res_config_pgsql.c

index 86cc25c86e586594f71e83927113362af7b31e36..fc2b8fa1b93b8b39f3842b716d9cb201ed030f70 100644 (file)
@@ -419,7 +419,7 @@ static struct ast_config *realtime_multi_odbc(const char *database, const char *
                        if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
                                ast_log(LOG_WARNING, "SQL Describe Column error!\n[%s]\n\n", sql);
                                ast_category_destroy(cat);
-                               continue;
+                               goto next_sql_fetch;
                        }
 
                        indicator = 0;
@@ -430,7 +430,7 @@ static struct ast_config *realtime_multi_odbc(const char *database, const char *
                        if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
                                ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
                                ast_category_destroy(cat);
-                               continue;
+                               goto next_sql_fetch;
                        }
                        stringp = rowdata;
                        while (stringp) {
@@ -448,6 +448,7 @@ static struct ast_config *realtime_multi_odbc(const char *database, const char *
                        }
                }
                ast_category_append(cfg, cat);
+next_sql_fetch:;
        }
 
        SQLFreeHandle(SQL_HANDLE_STMT, stmt);
index c83703db38ba8ea8249452d1ff7b1c96f0334ef4..d726d133fa66e503a3cb0901944b060a48066f76 100644 (file)
@@ -474,6 +474,7 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char
                        PQfinish(pgsqlConn);
                        pgsqlConn = NULL;
                }
+               ast_config_destroy(cfg);
                return NULL;
        }
 
@@ -494,6 +495,7 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char
        if (pgresult) {
                ast_log(LOG_ERROR, "Postgres detected invalid input: '%s'\n", newval);
                va_end(ap);
+               ast_config_destroy(cfg);
                return NULL;
        }
 
@@ -509,6 +511,7 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char
                if (pgresult) {
                        ast_log(LOG_ERROR, "Postgres detected invalid input: '%s'\n", newval);
                        va_end(ap);
+                       ast_config_destroy(cfg);
                        return NULL;
                }
 
@@ -525,6 +528,7 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char
        ast_mutex_lock(&pgsql_lock);
        if (!pgsql_reconnect(database)) {
                ast_mutex_unlock(&pgsql_lock);
+               ast_config_destroy(cfg);
                return NULL;
        }
 
@@ -534,6 +538,7 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char
                ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql));
                ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s\n", PQerrorMessage(pgsqlConn));
                ast_mutex_unlock(&pgsql_lock);
+               ast_config_destroy(cfg);
                return NULL;
        } else {
                ExecStatusType result_status = PQresultStatus(result);
@@ -547,6 +552,7 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char
                                                PQresultErrorMessage(result), PQresStatus(result_status));
                        PQclear(result);
                        ast_mutex_unlock(&pgsql_lock);
+                       ast_config_destroy(cfg);
                        return NULL;
                }
        }
@@ -564,6 +570,7 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char
                if (!(fieldnames = ast_calloc(1, numFields * sizeof(char *)))) {
                        PQclear(result);
                        ast_mutex_unlock(&pgsql_lock);
+                       ast_config_destroy(cfg);
                        return NULL;
                }
                for (i = 0; i < numFields; i++)