Seg fault on PQconnectdb

Started by Joe La Friteover 15 years ago4 messagesgeneral
Jump to latest
#1Joe La Frite
joelafrite84@gmail.com

Hi everyone,

I'm trying to use libpq in my application, but it crashes with a seg fault
when trying to connect. The call stack is as follows : malloc_consolidate <
_int_malloc < malloc < makeEmptyPGconn < PQconnectStart < PQconnectdb < my
own application.

I have no clue as to what causes this. Sample programs that only do a call
to PQconnectdb work fine. My application uses a complex build script so I
suspect it may be a compiling or linking problem, but there are no errors
reported, and ldd points to the correct version of libpq.so.

I've tried googling but could not find anything useful. I would really
appreciate some help. Thanks in advance!

(English is not my first language so I apologize if there are mistakes or
I'm not being very clear.)

Joe L.F.

#2Merlin Moncure
mmoncure@gmail.com
In reply to: Joe La Frite (#1)
Re: Seg fault on PQconnectdb

On Wed, Oct 13, 2010 at 5:24 AM, Joe La Frite <joelafrite84@gmail.com> wrote:

Hi everyone,
I'm trying to use libpq in my application, but it crashes with a seg fault
when trying to connect. The call stack is as follows : malloc_consolidate <
_int_malloc < malloc < makeEmptyPGconn < PQconnectStart < PQconnectdb < my
own application.
I have no clue as to what causes this. Sample programs that only do a call
to PQconnectdb work fine. My application uses a complex build script so I
suspect it may be a compiling or linking problem, but there are no errors
reported, and ldd points to the correct version of libpq.so.
I've tried googling but could not find anything useful. I would really
appreciate some help. Thanks in advance!
(English is not my first language so I apologize if there are mistakes or
I'm not being very clear.)
Joe L.F.

hm, crashing in malloc. is your application multi threaded?

merlin

#3Joe La Frite
joelafrite84@gmail.com
In reply to: Merlin Moncure (#2)
Re: Seg fault on PQconnectdb

On Wed, Oct 13, 2010 at 16:06, Merlin Moncure <mmoncure@gmail.com> wrote:

On Wed, Oct 13, 2010 at 5:24 AM, Joe La Frite <joelafrite84@gmail.com> wrote:

Hi everyone,
I'm trying to use libpq in my application, but it crashes with a seg fault
when trying to connect. The call stack is as follows : malloc_consolidate <
_int_malloc < malloc < makeEmptyPGconn < PQconnectStart < PQconnectdb < my
own application.
I have no clue as to what causes this. Sample programs that only do a call
to PQconnectdb work fine. My application uses a complex build script so I
suspect it may be a compiling or linking problem, but there are no errors
reported, and ldd points to the correct version of libpq.so.
I've tried googling but could not find anything useful. I would really
appreciate some help. Thanks in advance!
(English is not my first language so I apologize if there are mistakes or
I'm not being very clear.)
Joe L.F.

hm, crashing in malloc.  is your application multi threaded?

merlin

No, single thread only.

Tough after some testing, I'm fairly sure the problem isn't caused by
libpq at all. I think the heap gets corrupted at some point before the
call to PQconnectdb is made, as replacing the call by a simple void*
test = malloc(10) causes it to crash as well.

Thanks for replying anyway. :)

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Joe La Frite (#3)
Re: Seg fault on PQconnectdb

Joe La Frite <joelafrite84@gmail.com> writes:

Tough after some testing, I'm fairly sure the problem isn't caused by
libpq at all. I think the heap gets corrupted at some point before the
call to PQconnectdb is made, as replacing the call by a simple void*
test = malloc(10) causes it to crash as well.

Yeah, a crash inside malloc almost certainly means that you've stomped
on some of malloc's internal data structures, probably by overrunning
the allocated size of some malloc'd data chunk. I'd suggest valgrind,
ElectricFence, or similar for locating the offending code.

regards, tom lane