[libpq] Segmentation fault when call PQfinish inside singletone pattern

From: Ilya Galdin <mymainwilliw(at)gmail(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: [libpq] Segmentation fault when call PQfinish inside singletone pattern
Date: 2019-07-02 12:56:49
Message-ID: CAG2ZDR79GgZqFFd=RHnmk=QuU9rHoCmzvPJxLgSoO1da53XizA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

I'm create singletone class, and want to add inside PGconn object.

This class, in the past, will provide connections to DB.

// postgresql#include
<libpq-fe.h>//==============================================================================class
TestST{public:
static TestST& getInstance()
{
static TestST test;
return test;
}
bool createConnection()
{
mConn.reset( PQsetdbLogin("localhost", "5432", NULL, NULL,
"test_db", "user_app",
"passwd"),
&PQfinish); // [SIGSEGV when delete] passing a
reference to the destroy function
return true;
}
private:
TestST()
{

}private:
std::shared_ptr<PGconn> mConn; // smart pointer to postgres connetion object};
//==============================================================================int
main(int argc, char** argv){
TestST::getInstance().createConnection(); // create singletone and connection

return 0;}//==============================================================================

When singletone is deleted, function PQfinish calls signal Segmentation
fault.

But If I move the initialization of mConn to the constructor - it's work.
If I build and run on windows (MSVC) - it's work.

postgres version 9.6.9; OS - Debian 9; gcc version 6.3.0

Faithfully yours Ilya Galdin

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David Rowley 2019-07-02 13:13:25 Re: GROUP BY and inheritance issue
Previous Message David Rowley 2019-07-02 12:55:35 Re: BUG #15882: Select .... UNION ALL