Re: [libpq] Segmentation fault when call PQfinish inside singletone pattern - Mailing list pgsql-bugs

From Robert Haas
Subject Re: [libpq] Segmentation fault when call PQfinish inside singletone pattern
Date
Msg-id CA+Tgmobh=mbwXuRc43uEBY7AB_mbYXvGnFjcGw5NGXiQaCj8Kw@mail.gmail.com
Whole thread Raw
In response to [libpq] Segmentation fault when call PQfinish inside singletone pattern  (Ilya Galdin <mymainwilliw@gmail.com>)
List pgsql-bugs
On Tue, Jul 2, 2019 at 9:32 AM Ilya Galdin <mymainwilliw@gmail.com> wrote:
> 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.

I doubt that this is a bug in PostgreSQL. Admittedly, I also don't see
what's wrong with your C++ code.  I tested here and it works OK for
me.  All the same, I suspect the issue is more likely to be there than
in PQfinish, which just closes the connection and frees associated
memory.  If you're getting a segmentation fault inside that function,
a likely reason is that the pointer you're passing to PQfinish is not
valid. You might be able to confirm or refute this theory by running
the failing program inside a debugger. Then, you can get a backtrace
at the point of the segmentation fault, and you can also print out the
values of key variables and see whether, for example, the PGconn looks
mostly OK with maybe one bad pointer someplace, or whether it's all
garbage.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



pgsql-bugs by date:

Previous
From: Robert Haas
Date:
Subject: Re: BUG #15886: I cannot install postgres
Next
From: Tom Lane
Date:
Subject: Re: BUG #15897: make failed postgres 11.4 at 32 bit build