Re: [libpq] Segmentation fault when call PQfinish inside singletone pattern
On Tue, Jul 2, 2019 at 9:32 AM Ilya Galdin <[hidden email]> 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