creating a pgconnection (or pgdatabase) object on the heap gives segmentation fault...

From: "ravindranathm" <ravindranathm(at)integramicro(dot)com>
To: <pgsql-bugs(at)postgresql(dot)org>
Subject: creating a pgconnection (or pgdatabase) object on the heap gives segmentation fault...
Date: 2001-03-22 14:57:28
Message-ID: 001601c0b2e0$6a15b5c0$cfc809c0@rv
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi...

find the following details about the bug and please send a response/bugfix.

------------------------------
Testing platform details...
Postgress Version : 7.0.3
Platform : Linux 6.2 on a Compaq Server
System Memory : 1 GB
Disk Space : 6 GB
library : libpq++

Bug description...
1 - Try to create a PgConnection object or a PgDatabase object on the heap using new
PgDatabase *conn = new PgDatabase ("user=xyz dbname=abc");
or
PgConnection *conn = new PgConnection ("user=xyz dbname=abc");

Execute the program after compiling. When the above is executed you get the following error:
Segmentation fault (core dumped)

Note: If you create on the stack using
PgDatabase conn = PgDatabase ("user=xyz dbname=abc");
or
PgConnection conn = PgConnection ("user=xyz dbname=abc");
then, it works.

2. - No default constructor available for connection object
A call like
PgDatabase conn = PgConnection;
will not compile and gives an error message saying...
PgDatabase::PgDatabase() is protected.

Therefore, If one wants to create an array of connections, (for ex: to implement a connection pool),
a call like PgConnection conns[CONNECTIONS]; won;t work.

To overcome the above 2 problems, we tried creating a class by inheriting from pgDatabase, which provides a
default constructor.
ex:
class mydb : public PgDatabase {
public:
mydb() : PgDatabase() { }
mydb(string& constr) : PgDtabase (constr.c_str()) { }
};

Then the function calls:
mydb* con1 = new mydb();
mydb* con2 = new mydb("user=xyz dbname=abc");
are working properly...
but...
then the calls to free the memory give segmentation fault.
delete con1;
delete con2;

Please kindly, check the above and let me know that my analysis is correct or wrong.
In previous version of postgres i.e. 6.x, this problem does not exist. Also find
herewith attached some sample code, we used for testing...

sincerely...

Ravindranath M

Attachment Content-Type Size
pgtest.cpp application/octet-stream 1.2 KB

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2001-03-22 15:19:25 Re: Tests randomly failed
Previous Message Peter T Mount 2001-03-22 14:46:43 Re: JDBC and getTimestamp() exception