mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-16 14:58:25 +00:00
Add assertions in the quest to track down a refcount leak.
(closes issue #14485) Reported by: davevg git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@176592 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -338,8 +338,10 @@ static int acf_odbc_write(struct ast_channel *chan, const char *cmd, char *s, co
|
|||||||
SQLCloseCursor(stmt);
|
SQLCloseCursor(stmt);
|
||||||
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
||||||
}
|
}
|
||||||
if (obj)
|
if (obj) {
|
||||||
ast_odbc_release_obj(obj);
|
ast_odbc_release_obj(obj);
|
||||||
|
obj = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (chan)
|
if (chan)
|
||||||
ast_autoservice_stop(chan);
|
ast_autoservice_stop(chan);
|
||||||
@@ -443,6 +445,7 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
|
|||||||
ast_log(LOG_ERROR, "Unable to execute query [%s]\n", ast_str_buffer(sql));
|
ast_log(LOG_ERROR, "Unable to execute query [%s]\n", ast_str_buffer(sql));
|
||||||
if (obj) {
|
if (obj) {
|
||||||
ast_odbc_release_obj(obj);
|
ast_odbc_release_obj(obj);
|
||||||
|
obj = NULL;
|
||||||
}
|
}
|
||||||
pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
|
pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
|
||||||
if (chan) {
|
if (chan) {
|
||||||
@@ -460,6 +463,7 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
|
|||||||
SQLCloseCursor(stmt);
|
SQLCloseCursor(stmt);
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
ast_odbc_release_obj(obj);
|
ast_odbc_release_obj(obj);
|
||||||
|
obj = NULL;
|
||||||
pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
|
pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
|
||||||
if (chan) {
|
if (chan) {
|
||||||
ast_autoservice_stop(chan);
|
ast_autoservice_stop(chan);
|
||||||
@@ -486,6 +490,7 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
|
|||||||
SQLCloseCursor(stmt);
|
SQLCloseCursor(stmt);
|
||||||
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
||||||
ast_odbc_release_obj(obj);
|
ast_odbc_release_obj(obj);
|
||||||
|
obj = NULL;
|
||||||
pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
|
pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
|
||||||
pbx_builtin_setvar_helper(chan, "ODBCSTATUS", status);
|
pbx_builtin_setvar_helper(chan, "ODBCSTATUS", status);
|
||||||
if (chan)
|
if (chan)
|
||||||
@@ -528,6 +533,7 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
|
|||||||
SQLCloseCursor(stmt);
|
SQLCloseCursor(stmt);
|
||||||
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
||||||
ast_odbc_release_obj(obj);
|
ast_odbc_release_obj(obj);
|
||||||
|
obj = NULL;
|
||||||
pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
|
pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
|
||||||
pbx_builtin_setvar_helper(chan, "ODBCSTATUS", "MEMERROR");
|
pbx_builtin_setvar_helper(chan, "ODBCSTATUS", "MEMERROR");
|
||||||
if (chan)
|
if (chan)
|
||||||
@@ -625,6 +631,7 @@ end_acf_read:
|
|||||||
SQLCloseCursor(stmt);
|
SQLCloseCursor(stmt);
|
||||||
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
||||||
ast_odbc_release_obj(obj);
|
ast_odbc_release_obj(obj);
|
||||||
|
obj = NULL;
|
||||||
if (chan)
|
if (chan)
|
||||||
ast_autoservice_stop(chan);
|
ast_autoservice_stop(chan);
|
||||||
if (bogus_chan)
|
if (bogus_chan)
|
||||||
@@ -637,6 +644,7 @@ end_acf_read:
|
|||||||
SQLCloseCursor(stmt);
|
SQLCloseCursor(stmt);
|
||||||
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
||||||
ast_odbc_release_obj(obj);
|
ast_odbc_release_obj(obj);
|
||||||
|
obj = NULL;
|
||||||
if (chan)
|
if (chan)
|
||||||
ast_autoservice_stop(chan);
|
ast_autoservice_stop(chan);
|
||||||
if (bogus_chan)
|
if (bogus_chan)
|
||||||
@@ -1056,6 +1064,7 @@ static char *cli_odbc_read(struct ast_cli_entry *e, int cmd, struct ast_cli_args
|
|||||||
ast_debug(1, "Got obj\n");
|
ast_debug(1, "Got obj\n");
|
||||||
if (!(stmt = ast_odbc_direct_execute(obj, generic_execute, ast_str_buffer(sql)))) {
|
if (!(stmt = ast_odbc_direct_execute(obj, generic_execute, ast_str_buffer(sql)))) {
|
||||||
ast_odbc_release_obj(obj);
|
ast_odbc_release_obj(obj);
|
||||||
|
obj = NULL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1067,6 +1076,7 @@ static char *cli_odbc_read(struct ast_cli_entry *e, int cmd, struct ast_cli_args
|
|||||||
SQLCloseCursor(stmt);
|
SQLCloseCursor(stmt);
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
ast_odbc_release_obj(obj);
|
ast_odbc_release_obj(obj);
|
||||||
|
obj = NULL;
|
||||||
AST_RWLIST_UNLOCK(&queries);
|
AST_RWLIST_UNLOCK(&queries);
|
||||||
return CLI_SUCCESS;
|
return CLI_SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -1076,6 +1086,7 @@ static char *cli_odbc_read(struct ast_cli_entry *e, int cmd, struct ast_cli_args
|
|||||||
SQLCloseCursor(stmt);
|
SQLCloseCursor(stmt);
|
||||||
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
||||||
ast_odbc_release_obj(obj);
|
ast_odbc_release_obj(obj);
|
||||||
|
obj = NULL;
|
||||||
if (res == SQL_NO_DATA) {
|
if (res == SQL_NO_DATA) {
|
||||||
ast_cli(a->fd, "Returned %d rows. Query executed on handle %d:%s [%s]\n", rows, dsn, query->readhandle[dsn], ast_str_buffer(sql));
|
ast_cli(a->fd, "Returned %d rows. Query executed on handle %d:%s [%s]\n", rows, dsn, query->readhandle[dsn], ast_str_buffer(sql));
|
||||||
break;
|
break;
|
||||||
@@ -1103,27 +1114,33 @@ static char *cli_odbc_read(struct ast_cli_entry *e, int cmd, struct ast_cli_args
|
|||||||
SQLCloseCursor(stmt);
|
SQLCloseCursor(stmt);
|
||||||
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
||||||
ast_odbc_release_obj(obj);
|
ast_odbc_release_obj(obj);
|
||||||
|
obj = NULL;
|
||||||
AST_RWLIST_UNLOCK(&queries);
|
AST_RWLIST_UNLOCK(&queries);
|
||||||
return CLI_SUCCESS;
|
return CLI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_cli(a->fd, "%-20.20s %s\n", colname, ast_str_buffer(coldata));
|
ast_cli(a->fd, "%-20.20s %s\n", colname, ast_str_buffer(coldata));
|
||||||
}
|
}
|
||||||
|
rows++;
|
||||||
|
|
||||||
/* Get next row */
|
/* Get next row */
|
||||||
res = SQLFetch(stmt);
|
res = SQLFetch(stmt);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ast_cli(a->fd, "%-20.20s %s\n", "----------", "----------");
|
ast_cli(a->fd, "%-20.20s %s\n", "----------", "----------");
|
||||||
rows++;
|
|
||||||
}
|
}
|
||||||
SQLCloseCursor(stmt);
|
SQLCloseCursor(stmt);
|
||||||
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
||||||
ast_odbc_release_obj(obj);
|
ast_odbc_release_obj(obj);
|
||||||
ast_cli(a->fd, "Returned %d rows. Query executed on handle %d [%s]\n", rows, dsn, query->readhandle[dsn]);
|
obj = NULL;
|
||||||
|
ast_cli(a->fd, "Returned %d row%s. Query executed on handle %d [%s]\n", rows, rows == 1 ? "" : "s", dsn, query->readhandle[dsn]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ast_odbc_release_obj(obj);
|
if (obj) {
|
||||||
|
ast_odbc_release_obj(obj);
|
||||||
|
obj = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!executed) {
|
if (!executed) {
|
||||||
ast_cli(a->fd, "Failed to execute query. [%s]\n", ast_str_buffer(sql));
|
ast_cli(a->fd, "Failed to execute query. [%s]\n", ast_str_buffer(sql));
|
||||||
@@ -1252,6 +1269,7 @@ static char *cli_odbc_write(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
|
|||||||
}
|
}
|
||||||
if (!(stmt = ast_odbc_direct_execute(obj, generic_execute, ast_str_buffer(sql)))) {
|
if (!(stmt = ast_odbc_direct_execute(obj, generic_execute, ast_str_buffer(sql)))) {
|
||||||
ast_odbc_release_obj(obj);
|
ast_odbc_release_obj(obj);
|
||||||
|
obj = NULL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1259,6 +1277,7 @@ static char *cli_odbc_write(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
|
|||||||
SQLCloseCursor(stmt);
|
SQLCloseCursor(stmt);
|
||||||
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
||||||
ast_odbc_release_obj(obj);
|
ast_odbc_release_obj(obj);
|
||||||
|
obj = NULL;
|
||||||
ast_cli(a->fd, "Affected %d rows. Query executed on handle %d [%s]\n", (int)rows, dsn, query->writehandle[dsn]);
|
ast_cli(a->fd, "Affected %d rows. Query executed on handle %d [%s]\n", (int)rows, dsn, query->writehandle[dsn]);
|
||||||
executed = 1;
|
executed = 1;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -100,9 +100,11 @@ static int null_hash_fn(const void *obj, const int flags)
|
|||||||
static void odbc_obj_destructor(void *data)
|
static void odbc_obj_destructor(void *data)
|
||||||
{
|
{
|
||||||
struct odbc_obj *obj = data;
|
struct odbc_obj *obj = data;
|
||||||
|
struct odbc_class *class = obj->parent;
|
||||||
|
obj->parent = NULL;
|
||||||
odbc_obj_disconnect(obj);
|
odbc_obj_disconnect(obj);
|
||||||
ast_mutex_destroy(&obj->lock);
|
ast_mutex_destroy(&obj->lock);
|
||||||
ao2_ref(obj->parent, -1);
|
ao2_ref(class, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroy_table_cache(struct odbc_cache_tables *table) {
|
static void destroy_table_cache(struct odbc_cache_tables *table) {
|
||||||
@@ -573,10 +575,11 @@ static char *handle_cli_odbc_show(struct ast_cli_entry *e, int cmd, struct ast_c
|
|||||||
while ((class = ao2_iterator_next(&aoi))) {
|
while ((class = ao2_iterator_next(&aoi))) {
|
||||||
if (!strncasecmp(a->word, class->name, length) && ++which > a->n) {
|
if (!strncasecmp(a->word, class->name, length) && ++which > a->n) {
|
||||||
ret = ast_strdup(class->name);
|
ret = ast_strdup(class->name);
|
||||||
ao2_ref(class, -1);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
ao2_ref(class, -1);
|
ao2_ref(class, -1);
|
||||||
|
if (ret) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!ret && !strncasecmp(a->word, "all", length) && ++which > a->n) {
|
if (!ret && !strncasecmp(a->word, "all", length) && ++which > a->n) {
|
||||||
ret = ast_strdup("all");
|
ret = ast_strdup("all");
|
||||||
@@ -691,6 +694,8 @@ struct odbc_obj *ast_odbc_request_obj(const char *name, int check)
|
|||||||
if (!class)
|
if (!class)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
ast_assert(ao2_ref(class, 0) > 1);
|
||||||
|
|
||||||
if (class->haspool) {
|
if (class->haspool) {
|
||||||
/* Recycle connections before building another */
|
/* Recycle connections before building another */
|
||||||
aoi = ao2_iterator_init(class->obj_container, 0);
|
aoi = ao2_iterator_init(class->obj_container, 0);
|
||||||
@@ -704,6 +709,10 @@ struct odbc_obj *ast_odbc_request_obj(const char *name, int check)
|
|||||||
ao2_ref(obj, -1);
|
ao2_ref(obj, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (obj) {
|
||||||
|
ast_assert(ao2_ref(obj, 0) > 1);
|
||||||
|
}
|
||||||
|
|
||||||
if (!obj && (class->count < class->limit)) {
|
if (!obj && (class->count < class->limit)) {
|
||||||
class->count++;
|
class->count++;
|
||||||
obj = ao2_alloc(sizeof(*obj), odbc_obj_destructor);
|
obj = ao2_alloc(sizeof(*obj), odbc_obj_destructor);
|
||||||
@@ -711,12 +720,14 @@ struct odbc_obj *ast_odbc_request_obj(const char *name, int check)
|
|||||||
ao2_ref(class, -1);
|
ao2_ref(class, -1);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
ast_assert(ao2_ref(obj, 0) == 1);
|
||||||
ast_mutex_init(&obj->lock);
|
ast_mutex_init(&obj->lock);
|
||||||
/* obj inherits the outstanding reference to class */
|
/* obj inherits the outstanding reference to class */
|
||||||
obj->parent = class;
|
obj->parent = class;
|
||||||
if (odbc_obj_connect(obj) == ODBC_FAIL) {
|
if (odbc_obj_connect(obj) == ODBC_FAIL) {
|
||||||
ast_log(LOG_WARNING, "Failed to connect to %s\n", name);
|
ast_log(LOG_WARNING, "Failed to connect to %s\n", name);
|
||||||
ao2_ref(obj, -1);
|
ao2_ref(obj, -1);
|
||||||
|
ast_assert(ao2_ref(class, 0) > 0);
|
||||||
obj = NULL;
|
obj = NULL;
|
||||||
} else {
|
} else {
|
||||||
obj->used = 1;
|
obj->used = 1;
|
||||||
@@ -738,12 +749,14 @@ struct odbc_obj *ast_odbc_request_obj(const char *name, int check)
|
|||||||
|
|
||||||
if (obj) {
|
if (obj) {
|
||||||
/* Object is not constructed, so delete outstanding reference to class. */
|
/* Object is not constructed, so delete outstanding reference to class. */
|
||||||
|
ast_assert(ao2_ref(class, 0) > 1);
|
||||||
ao2_ref(class, -1);
|
ao2_ref(class, -1);
|
||||||
class = NULL;
|
class = NULL;
|
||||||
} else {
|
} else {
|
||||||
/* No entry: build one */
|
/* No entry: build one */
|
||||||
obj = ao2_alloc(sizeof(*obj), odbc_obj_destructor);
|
obj = ao2_alloc(sizeof(*obj), odbc_obj_destructor);
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
|
ast_assert(ao2_ref(class, 0) > 1);
|
||||||
ao2_ref(class, -1);
|
ao2_ref(class, -1);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -756,6 +769,7 @@ struct odbc_obj *ast_odbc_request_obj(const char *name, int check)
|
|||||||
obj = NULL;
|
obj = NULL;
|
||||||
} else {
|
} else {
|
||||||
ao2_link(class->obj_container, obj);
|
ao2_link(class->obj_container, obj);
|
||||||
|
ast_assert(ao2_ref(obj, 0) > 1);
|
||||||
}
|
}
|
||||||
class = NULL;
|
class = NULL;
|
||||||
}
|
}
|
||||||
@@ -775,6 +789,9 @@ struct odbc_obj *ast_odbc_request_obj(const char *name, int check)
|
|||||||
#endif
|
#endif
|
||||||
ast_assert(class == NULL);
|
ast_assert(class == NULL);
|
||||||
|
|
||||||
|
if (obj) {
|
||||||
|
ast_assert(ao2_ref(obj, 0) > 1);
|
||||||
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -794,10 +811,12 @@ static odbc_status odbc_obj_disconnect(struct odbc_obj *obj)
|
|||||||
|
|
||||||
res = SQLDisconnect(obj->con);
|
res = SQLDisconnect(obj->con);
|
||||||
|
|
||||||
if (res == SQL_SUCCESS || res == SQL_SUCCESS_WITH_INFO) {
|
if (obj->parent) {
|
||||||
ast_log(LOG_DEBUG, "Disconnected %d from %s [%s]\n", res, obj->parent->name, obj->parent->dsn);
|
if (res == SQL_SUCCESS || res == SQL_SUCCESS_WITH_INFO) {
|
||||||
} else {
|
ast_log(LOG_DEBUG, "Disconnected %d from %s [%s]\n", res, obj->parent->name, obj->parent->dsn);
|
||||||
ast_log(LOG_DEBUG, "res_odbc: %s [%s] already disconnected\n", obj->parent->name, obj->parent->dsn);
|
} else {
|
||||||
|
ast_log(LOG_DEBUG, "res_odbc: %s [%s] already disconnected\n", obj->parent->name, obj->parent->dsn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((res = SQLFreeHandle(SQL_HANDLE_DBC, obj->con) == SQL_SUCCESS)) {
|
if ((res = SQLFreeHandle(SQL_HANDLE_DBC, obj->con) == SQL_SUCCESS)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user