Do not use already free'ed errmsg, bug found by Joachim Wieland
authorMichael Meskes <[email protected]>
Mon, 19 Jun 2006 09:20:22 +0000 (09:20 +0000)
committerMichael Meskes <[email protected]>
Mon, 19 Jun 2006 09:20:22 +0000 (09:20 +0000)
<[email protected]>

src/interfaces/ecpg/ecpglib/connect.c

index d8d32dbd76869b84da414c61d00f2f6afb0c40e0..6269abb99864512dd36dac8fb499342d9e035748 100644 (file)
@@ -451,10 +451,6 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
                const char *errmsg = PQerrorMessage(this->connection);
                char       *db = realname ? realname : "<DEFAULT>";
 
-               ecpg_finish(this);
-#ifdef ENABLE_THREAD_SAFETY
-               pthread_mutex_unlock(&connections_mutex);
-#endif
                ECPGlog("connect: could not open database %s on %s port %s %s%s%s%s in line %d\n\t%s\n",
                                db,
                                host ? host : "<DEFAULT>",
@@ -463,6 +459,11 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
                                user ? "for user " : "", user ? user : "",
                                lineno, errmsg);
 
+               ecpg_finish(this);
+#ifdef ENABLE_THREAD_SAFETY
+               pthread_mutex_unlock(&connections_mutex);
+#endif
+
                ECPGraise(lineno, ECPG_CONNECT, ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION, db);
                if (host)
                        ECPGfree(host);