From: Marko Ristola <Marko.Ristola@kolumbus.fi>
To: Dave Page <dpage@vale-housing.co.uk>
Cc: pgsql-odbc@postgresql.org
Subject: Re: psqlodbc libpq version: quiet error on connect failure
Date: Wed, 20 Jul 2005 16:22:16 +0300
Message-ID: <42DE5008.3090105@kolumbus.fi> (raw)
In-Reply-To: <E7F85A1B5FF8D44C8A1AF6885BC9A0E4AC93B4@ratbert.vale-housing.co.uk>
References: <E7F85A1B5FF8D44C8A1AF6885BC9A0E4AC93B4@ratbert.vale-housing.co.uk>
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
>
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-odbc@postgresql.org
Cc: Marko.Ristola@kolumbus.fi, dpage@vale-housing.co.uk
Subject: Re: psqlodbc libpq version: quiet error on connect failure
In-Reply-To: <42DE5008.3090105@kolumbus.fi>
References: <E7F85A1B5FF8D44C8A1AF6885BC9A0E4AC93B4@ratbert.vale-housing.co.uk> <42DE5008.3090105@kolumbus.fi>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox