Re: [libpq] Segmentation fault when call PQfinish inside singletone pattern

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Ilya Galdin <mymainwilliw(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: [libpq] Segmentation fault when call PQfinish inside singletone pattern
Date: 2019-07-05 13:54:37
Message-ID: CA+Tgmobh=mbwXuRc43uEBY7AB_mbYXvGnFjcGw5NGXiQaCj8Kw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, Jul 2, 2019 at 9:32 AM Ilya Galdin <mymainwilliw(at)gmail(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2019-07-05 14:12:13 Re: BUG #15897: make failed postgres 11.4 at 32 bit build
Previous Message Robert Haas 2019-07-05 13:33:27 Re: BUG #15886: I cannot install postgres