From 89588a043facd19911a47c57d752b025ccfb99d5 Mon Sep 17 00:00:00 2001
From: Tilghman Lesher <tilghman@meg.abyt.es>
Date: Sat, 11 Aug 2007 05:28:08 +0000
Subject: [PATCH] Merged revisions 79142 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r79142 | tilghman | 2007-08-11 00:23:04 -0500 (Sat, 11 Aug 2007) | 2 lines

Ensure the connection gets marked as used at allocation time (closes issue #10429, report and fix by mnicholson)

........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@79147 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 res/res_odbc.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/res/res_odbc.c b/res/res_odbc.c
index c46029f022..d688930c15 100644
--- a/res/res_odbc.c
+++ b/res/res_odbc.c
@@ -416,8 +416,16 @@ struct odbc_obj *ast_odbc_request_obj(const char *name, int check)
 			}
 			ast_mutex_init(&obj->lock);
 			obj->parent = class;
-			odbc_obj_connect(obj);
-			AST_LIST_INSERT_TAIL(&class->odbc_obj, obj, list);
+			if (odbc_obj_connect(obj) == ODBC_FAIL) {
+				ast_log(LOG_WARNING, "Failed to connect to %s\n", name);
+				ast_mutex_destroy(&obj->lock);
+				free(obj);
+				obj = NULL;
+				class->count--;
+			} else {
+				obj->used = 1;
+				AST_LIST_INSERT_TAIL(&class->odbc_obj, obj, list);
+			}
 		}
 	} else {
 		/* Non-pooled connection: multiple modules can use the same connection. */
-- 
GitLab