Fix crashes in res_odbc.
authorMark Michelson <mmichelson@digium.com>
Thu, 18 Dec 2008 19:34:33 +0000 (19:34 +0000)
committerMark Michelson <mmichelson@digium.com>
Thu, 18 Dec 2008 19:34:33 +0000 (19:34 +0000)
The variable "class" was being set NULL just prior to
being dereferenced in an ao2_link call. I have moved
the setting of the variable to NULL until after the
ao2_link call.

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

res/res_odbc.c

index 8161fd3..5864c7d 100644 (file)
@@ -699,7 +699,6 @@ struct odbc_obj *ast_odbc_request_obj(const char *name, int check)
                        ast_mutex_init(&obj->lock);
                        /* obj inherits the outstanding reference to class */
                        obj->parent = class;
                        ast_mutex_init(&obj->lock);
                        /* obj inherits the outstanding reference to class */
                        obj->parent = class;
-                       class = NULL;
                        if (odbc_obj_connect(obj) == ODBC_FAIL) {
                                ast_log(LOG_WARNING, "Failed to connect to %s\n", name);
                                ao2_ref(obj, -1);
                        if (odbc_obj_connect(obj) == ODBC_FAIL) {
                                ast_log(LOG_WARNING, "Failed to connect to %s\n", name);
                                ao2_ref(obj, -1);
@@ -708,6 +707,7 @@ struct odbc_obj *ast_odbc_request_obj(const char *name, int check)
                                obj->used = 1;
                                ao2_link(class->obj_container, obj);
                        }
                                obj->used = 1;
                                ao2_link(class->obj_container, obj);
                        }
+                       class = NULL;
                } else {
                        /* Object is not constructed, so delete outstanding reference to class. */
                        ao2_ref(class, -1);
                } else {
                        /* Object is not constructed, so delete outstanding reference to class. */
                        ao2_ref(class, -1);
@@ -735,7 +735,6 @@ struct odbc_obj *ast_odbc_request_obj(const char *name, int check)
                        ast_mutex_init(&obj->lock);
                        /* obj inherits the outstanding reference to class */
                        obj->parent = class;
                        ast_mutex_init(&obj->lock);
                        /* obj inherits the outstanding reference to class */
                        obj->parent = class;
-                       class = NULL;
                        if (odbc_obj_connect(obj) == ODBC_FAIL) {
                                ast_log(LOG_WARNING, "Failed to connect to %s\n", name);
                                ao2_ref(obj, -1);
                        if (odbc_obj_connect(obj) == ODBC_FAIL) {
                                ast_log(LOG_WARNING, "Failed to connect to %s\n", name);
                                ao2_ref(obj, -1);
@@ -743,6 +742,7 @@ struct odbc_obj *ast_odbc_request_obj(const char *name, int check)
                        } else {
                                ao2_link(class->obj_container, obj);
                        }
                        } else {
                                ao2_link(class->obj_container, obj);
                        }
+                       class = NULL;
                }
        }
 
                }
        }