X-Original-To: pgsql-odbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6416252942 for ; Wed, 20 Jul 2005 10:22:28 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 69272-09 for ; Wed, 20 Jul 2005 13:22:11 +0000 (GMT) Received: from fep31-app.kolumbus.fi (fep31-0.kolumbus.fi [193.229.0.35]) by svr1.postgresql.org (Postfix) with ESMTP id 3CB31528A8 for ; Wed, 20 Jul 2005 10:22:08 -0300 (ADT) Received: from [192.168.1.102] (really [193.229.230.202]) by fep31-app.kolumbus.fi with ESMTP id <20050720132212.SUPX26099.fep31-app.kolumbus.fi@[192.168.1.102]>; Wed, 20 Jul 2005 16:22:12 +0300 Message-ID: <42DE5008.3090105@kolumbus.fi> Date: Wed, 20 Jul 2005 16:22:16 +0300 From: Marko Ristola User-Agent: Debian Thunderbird 1.0.2 (X11/20050331) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Dave Page Cc: pgsql-odbc@postgresql.org Subject: Re: psqlodbc libpq version: quiet error on connect failure References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.129 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200507/87 X-Sequence-Number: 5553 I found one small required fix: self->pgconn needs to be set as NULL after PQfinish(self->pgconn) on line 3117. Otherwise there comes a double free problem later. self->pgconn = PQconnectdb(conninfo); if (PQstatus(self->pgconn) != CONNECTION_OK) { CC_set_error(self,CONNECTION_COULD_NOT_ESTABLISH,PQerrorMessage(self->pgconn)); mylog("could not establish connection to the database %s \n",PQerrorMessage(self->pgconn)); PQfinish(self->pgconn); self->pgconn = NULL; //THIS IS THE FIX, THAT IS NEEDED TO AVOID THE DOUBLE free(). free(conninfo); return 0; } Marko Ristola Dave Page wrote: >Thanks, I've applied a patch to fix this. Iirc, exit_nicely() is used in >the libpq examples in the PostgreSQL manual :-) > >/D > > > >>-----Original Message----- >>From: pgsql-odbc-owner@postgresql.org >>[mailto:pgsql-odbc-owner@postgresql.org] On Behalf Of Marko Ristola >>Sent: 20 July 2005 12:23 >>To: pgsql-odbc@postgresql.org >>Subject: [ODBC] psqlodbc libpq version: quiet error on connect failure >> >> >>Problem >> >>psqlodbc, with libpq enabled, will do exit(1), if connecting into the >>database fails. >>A good fix seems to be to remove the exit_nicely() function call. >> >>---------------------- >>static void >>exit_nicely(PGconn *conn) >>{ >> PQfinish(conn); >> exit(1); >>} >>---------------------- >> >>Connect code: >> >> self->pgconn = PQconnectdb(conninfo); >> if (PQstatus(self->pgconn) != CONNECTION_OK) >> { >> >>CC_set_error(self,CONNECTION_COULD_NOT_ESTABLISH,PQerrorMessag >>e(self->pgconn)); >> mylog("could not establish connection to the database %s >>\n",PQerrorMessage(self->pgconn)); >> exit_nicely(self->pgconn); >> free(conninfo); >> return 0; >> } >> >>------------------------ >> >>Marko Ristola >> >> >>---------------------------(end of >>broadcast)--------------------------- >>TIP 5: don't forget to increase your free space map settings >> >> >> > >---------------------------(end of broadcast)--------------------------- >TIP 4: Have you searched our list archives? > > http://archives.postgresql.org > >