pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Multi-threaded user app segfaults when using libpq with separate connections
6+ messages / 2 participants
[nested] [flat]

* Multi-threaded user app segfaults when using libpq with separate connections
@ 2003-08-04 15:29 Frank van Vugt <ftm.van.vugt@foxi.nl>
  2003-08-04 15:47 ` Re: Multi-threaded user app segfaults when using libpq with separate connections Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 6+ messages in thread

From: Frank van Vugt @ 2003-08-04 15:29 UTC (permalink / raw)
  To: pgsql-interfaces

Your name		:		Frank van Vugt
Your email address	:	ftm.van.vugt@foxi.nl

System Configuration
---------------------
  Architecture  :
	Intel Pentium III / Amd Athlon XP+

  Operating System :
	Linux 2.4.20 with glibc 2.3.2 (SuSE v8.2)

  PostgreSQL version :
	PostgreSQL-7.3.4

  Compiler used :
	gcc v3.3


Please enter a FULL description of your problem:
------------------------------------------------

A small multi-threaded demo/poc-program using Qt (including its SQL-module 
which connects to PostgreSQL using libpq) is segfaulting while multiple 
connections are used.

The code creates 10 new threads, each of which basically:
- locks a mutex
- adds/opens a new database connection
- unlocks the mutex
- using the newly created/opened connection
  - starts a transaction
  - sets transaction isolation level to SERIALIZABLE
  - performs some select-only queries
  - commits the transaction
- closes the database connection


Out of 10 consecutive runs, the code completes three times successfully and 
segfaults the other seven times. I have recompiled libpq with debugging and 
without optimization, the backtraces of the coredumps are included below.


Important : if the unlocking of the mutex is moved to AFTER the database 
close, then the code seems to run without any problem each and every time



Please describe a way to repeat the problem.   Please try to provide a
concise reproducible example, if at all possible:
----------------------------------------------------------------------

I'm not sure how to proceed from here. Obviously I'm using Qt for handling 
PostgreSQL connections as well as multi-threading, so rewriting my
'demo-code' in plain C++ using libpthread and libpq would probably take too 
much time. Maybe someone is willing to have a go at the Qt-code (just let me 
know and I'll mail the source), or maybe (hopefully) the information provided 
here will prove sufficient a clue to pinpoint the problem.

The only thing I found in the mailinglist archives which *may* have some 
bearing to this problem is:
http://archives.postgresql.org/pgsql-interfaces/2002-09/msg00042.php

I'm not sure it's relevant, but please be advised that the PostgreSQL driver 
in Qt has the following code included in order to allow compilation:

// PostgreSQL header <utils/elog.h> included by <postgres.h> redefines DEBUG.
#if defined(DEBUG)
# undef DEBUG
#endif
#include <postgres.h>
#include <libpq/libpq-fs.h>
// PostgreSQL header <catalog/pg_type.h> redefines errno erroneously.
#if defined(errno)
# undef errno
#endif
#define errno qt_psql_errno
#include <catalog/pg_type.h>
#undef errno


Furthermore, I found that the 7.4devdocs talk about the --enable-thread-safety 
option for ./configure, but I don't think that applies to my platform?




=> backtraces of coredumps included below



Best,







Frank.


========================================================

The results of ten sequentially executed runs:

-+-+-+-

#0  0x40cc1b2b in realloc () from /lib/libc.so.6
(gdb) where
#0  0x40cc1b2b in realloc () from /lib/libc.so.6
#1  0x40d8c7ac in pqReadData (conn=0x80c0fc0) at fe-misc.c:483
#2  0x40d8a335 in PQgetResult (conn=0x80c0fc0) at fe-exec.c:1337
#3  0x40d8a511 in PQexec (conn=0x80c0fc0, query=0x80cb638 "set transaction 
isolation level SERIALIZABLE") at fe-exec.c:1441
#4  0x4063aaa7 in QPSQLResult::reset(QString const&) (this=0x80cb418, 
query=@0xbf7ffa9c) at sql/drivers/psql/qsql_psql.cpp:473
#5  0x4060dd34 in QSqlQuery::exec(QString const&) (this=0xbf7ffa8c, 
query=@0xbf7ffa9c) at sql/qsqlquery.cpp:358
#6  0x08050401 in PrintEngine::run() (this=0x80a72e0) at printengine.cpp:85
#7  0x402b4be6 in QThreadInstance::start(void*) (_arg=0x80a7374) at 
kernel/qthread_unix.cpp:120
#8  0x40b1dc60 in pthread_start_thread () from /lib/libpthread.so.0
(gdb)

-+-+-+-

#0  0x4061390d in QSqlDatabase::transaction() (this=0x80cd2e8) at 
sql/qsqldatabase.cpp:760
760         if ( !d->driver->hasFeature( QSqlDriver::Transactions ) )
(gdb) where
#0  0x4061390d in QSqlDatabase::transaction() (this=0x80cd2e8) at 
sql/qsqldatabase.cpp:760
#1  0x080503cb in PrintEngine::run() (this=0x80c0b98) at printengine.cpp:83
#2  0x402b4be6 in QThreadInstance::start(void*) (_arg=0x80c0bdc) at 
kernel/qthread_unix.cpp:120
#3  0x40b1dc60 in pthread_start_thread () from /lib/libpthread.so.0
(gdb)

-+-+-+-

Third run without problems.

-+-+-+-

Fourth run without problems.

-+-+-+-

#0  0x40caf675 in fflush () from /lib/libc.so.6
(gdb) where
#0  0x40caf675 in fflush () from /lib/libc.so.6
#1  0x40d8cc16 in pqSendSome (conn=0x80c10f8) at fe-misc.c:746
#2  0x40d8cc46 in pqFlush (conn=0x80c10f8) at fe-misc.c:764
#3  0x40d896e6 in PQsendQuery (conn=0x80c10f8, query=0x80cb3d0 "set 
transaction isolation level SERIALIZABLE") at fe-exec.c:799
#4  0x40d8a4f3 in PQexec (conn=0x80c10f8, query=0x80cb3d0 "set transaction 
isolation level SERIALIZABLE") at fe-exec.c:1429
#5  0x4063aaa7 in QPSQLResult::reset(QString const&) (this=0x80cb0f8, 
query=@0xbf7ffa9c) at sql/drivers/psql/qsql_psql.cpp:473
#6  0x4060dd34 in QSqlQuery::exec(QString const&) (this=0xbf7ffa8c, 
query=@0xbf7ffa9c) at sql/qsqlquery.cpp:358
#7  0x08050401 in PrintEngine::run() (this=0x80a72d0) at printengine.cpp:85
#8  0x402b4be6 in QThreadInstance::start(void*) (_arg=0x80a7364) at 
kernel/qthread_unix.cpp:120
#9  0x40b1dc60 in pthread_start_thread () from /lib/libpthread.so.0
(gdb)

-+-+-+-

#0  0x4061391e in QSqlDatabase::transaction() (this=0x80cbcb0) at 
sql/qsqldatabase.cpp:760
760         if ( !d->driver->hasFeature( QSqlDriver::Transactions ) )
(gdb) where
#0  0x4061391e in QSqlDatabase::transaction() (this=0x80cbcb0) at 
sql/qsqldatabase.cpp:760
#1  0x080503cb in PrintEngine::run() (this=0x80bd358) at printengine.cpp:83
#2  0x402b4be6 in QThreadInstance::start(void*) (_arg=0x80c0a74) at 
kernel/qthread_unix.cpp:120
#3  0x40b1dc60 in pthread_start_thread () from /lib/libpthread.so.0
(gdb)

-+-+-+-

#0  0x403352a1 in QObject::connect(QObject const*, char const*, QObject 
const*, char const*) (sender=0x80c0bf8, signal=0x80c0b58 "2destroyed()", 
receiver=0x80c7660, member=0x80c0c68 "1slotResultDestroyed()")
    at kernel/qobject.cpp:1737
1737        QMetaObject *smeta = sender->metaObject();
(gdb) where
#0  0x403352a1 in QObject::connect(QObject const*, char const*, QObject 
const*, char const*) (sender=0x80c0bf8, signal=0x80c0b58 "2destroyed()", 
receiver=0x80c7660, member=0x80c0c68 "1slotResultDestroyed()")
    at kernel/qobject.cpp:1737
#1  0x4060d07d in QSqlResultShared (this=0x80c7660, result=0x80cb080) at 
sql/qsqlquery.cpp:57
#2  0x4060d42f in QSqlQuery (this=0xbf7ff94c, r=0x80cb080) at 
sql/qsqlquery.cpp:213
#3  0x4063c03b in QPSQLDriver::createQuery() const (this=0x80c0bf8) at 
sql/drivers/psql/qsql_psql.cpp:687
#4  0x4060d874 in QSqlQuery::init(QString const&, QSqlDatabase*) 
(this=0xbf7ffa8c, query=@0x40a26a88, db=0x80c0ae8) at sql/qsqlquery.cpp:272
#5  0x4060d762 in QSqlQuery (this=0xbf7ffa8c, db=0x80c0ae8) at 
sql/qsqlquery.cpp:259
#6  0x080503dd in PrintEngine::run() (this=0x80a72e0) at printengine.cpp:84
#7  0x402b4be6 in QThreadInstance::start(void*) (_arg=0x80a7374) at 
kernel/qthread_unix.cpp:120
#8  0x40b1dc60 in pthread_start_thread () from /lib/libpthread.so.0
(gdb)

-+-+-+-

#0  0x4061396d in QSqlDatabase::commit() (this=0x80c0ae8) at 
sql/qsqldatabase.cpp:775
775         if ( !d->driver->hasFeature( QSqlDriver::Transactions ) )
(gdb) where
#0  0x4061396d in QSqlDatabase::commit() (this=0x80c0ae8) at 
sql/qsqldatabase.cpp:775
#1  0x08050b9d in PrintEngine::run() (this=0x80a72e0) at printengine.cpp:118
#2  0x402b4be6 in QThreadInstance::start(void*) (_arg=0x80a7374) at 
kernel/qthread_unix.cpp:120
#3  0x40b1dc60 in pthread_start_thread () from /lib/libpthread.so.0
(gdb)

-+-+-+-

Nineth run without problems

-+-+-+-

#0  0x40cc6a01 in strlen () from /lib/libc.so.6
(gdb) where
#0  0x40cc6a01 in strlen () from /lib/libc.so.6
#1  0x4071bf33 in internalLatin1ToUnicode (str=0xbf7ff89c "\b\021\f\b 
.¡@Äø\177¿êÀn@ .¡@üø\177¿Dù\177¿9¬c@üø\177¿,ù\177¿\002", len=0x83ffbbd8, 
maxlen=3212834996) at tools/qstring.cpp:1164
#2  0x4071cb0b in QString (this=0xbf7ff89c, str=0x83ffbbd8 <Address 0x83ffbbd8 
out of bounds>) at tools/qstring.cpp:1473
#3  0x40638d4f in qMakeError (err=@0xbf7ff92c, type=2, p=0x80ca2d0) at 
sql/drivers/psql/qsql_psql.cpp:118
#4  0x4063ac39 in QPSQLResult::reset(QString const&) (this=0x80ca5d8, 
query=@0xbf7ffa9c) at sql/drivers/psql/qsql_psql.cpp:489
#5  0x4060dd34 in QSqlQuery::exec(QString const&) (this=0xbf7ffa8c, 
query=@0xbf7ffa9c) at sql/qsqlquery.cpp:358
#6  0x08050401 in PrintEngine::run() (this=0x80a72e0) at printengine.cpp:85
#7  0x402b4be6 in QThreadInstance::start(void*) (_arg=0x80a7374) at 
kernel/qthread_unix.cpp:120
#8  0x40b1dc60 in pthread_start_thread () from /lib/libpthread.so.0
(gdb)

-+-+-+-





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Multi-threaded user app segfaults when using libpq with separate connections
  2003-08-04 15:29 Multi-threaded user app segfaults when using libpq with separate connections Frank van Vugt <ftm.van.vugt@foxi.nl>
@ 2003-08-04 15:47 ` Tom Lane <tgl@sss.pgh.pa.us>
  2003-08-04 22:34   ` Re: Multi-threaded user app segfaults when using libpq with separate connections Frank van Vugt <ftm.van.vugt@foxi.nl>
  0 siblings, 1 reply; 6+ messages in thread

From: Tom Lane @ 2003-08-04 15:47 UTC (permalink / raw)
  To: Frank van Vugt <ftm.van.vugt@foxi.nl>; +Cc: pgsql-interfaces

Frank van Vugt <ftm.van.vugt@foxi.nl> writes:
> // PostgreSQL header <catalog/pg_type.h> redefines errno erroneously.
> #if defined(errno)
> # undef errno
> #endif
> #define errno qt_psql_errno
> #include <catalog/pg_type.h>
> #undef errno

It seems highly unlikely that the above is a good idea.  errno is a
macro on all threaded platforms I'm aware of, but the above coding
forgets the definition.  The behavior complained of in the comment
is gone anyway in PG 7.3.

Not sure that this explains your problem though.

There are several places in libpq that invoke libc routines that are
not thread-safe (on most platforms anyway).  We have attempted to
rectify this for PG 7.4.  You may care to try your test with CVS tip and
see if it works better.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Multi-threaded user app segfaults when using libpq with separate connections
  2003-08-04 15:29 Multi-threaded user app segfaults when using libpq with separate connections Frank van Vugt <ftm.van.vugt@foxi.nl>
  2003-08-04 15:47 ` Re: Multi-threaded user app segfaults when using libpq with separate connections Tom Lane <tgl@sss.pgh.pa.us>
@ 2003-08-04 22:34   ` Frank van Vugt <ftm.van.vugt@foxi.nl>
  2003-08-04 22:41     ` Re: Multi-threaded user app segfaults when using libpq with separate connections Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 6+ messages in thread

From: Frank van Vugt @ 2003-08-04 22:34 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-interfaces

Hi Tom,

> It seems highly unlikely that the above is a good idea.  <cut>
> The behavior complained of in the comment
> is gone anyway in PG 7.3.

I've conveyed the message, thanks.

> You may care to try your test with CVS tip and see if it works better.

I've retried this with a cvs-version of this afternoon (local time). The build 
stranded in plpgsql (I seem to need a more recent bison), but at that point 
libpq was already finished. This still resulted in more or less the same kind 
of errors. I then retried with a cvs-version of 21:30 (utc), configured with 
enable-thread-safety and compiled with debug info / without optimization, 
along with a fresh compilation of Qt. 

Results : same diff (see errors below).


What more can I do to help out / find out what the problem is ?




Best,








Frank van Vugt

=+=+=+=+=+=+=+=+=+=+=+=+=+=

#0  0x4063ab77 in QPSQLResult::reset(QString const&) (this=0x80c10f0, 
query=@0xbf7ffa9c)
    at sql/drivers/psql/qsql_psql.cpp:477
477         int status =  PQresultStatus( d->result );
(gdb) where
#0  0x4063ab77 in QPSQLResult::reset(QString const&) (this=0x80c10f0, 
query=@0xbf7ffa9c)
    at sql/drivers/psql/qsql_psql.cpp:477
#1  0x4060dd44 in QSqlQuery::exec(QString const&) (this=0xbf7ffa8c, 
query=@0xbf7ffa9c) at sql/qsqlquery.cpp:358
#2  0x08050823 in PrintEngine::run() (this=0x809e2b8) at printengine.cpp:97
#3  0x402b4bf6 in QThreadInstance::start(void*) (_arg=0x809e31c) at 
kernel/qthread_unix.cpp:120
#4  0x40b1dc60 in pthread_start_thread () from /lib/libpthread.so.0
(gdb)


#0  0x40d8c85a in pqGetc (result=0xbf3ff81b "@8»Ù@ü\031\216@Dø?¿\035¬Ø@\210", 
conn=0x80d0088) at fe-misc.c:85
85       * write 1 char to the connection
(gdb) where
#0  0x40d8c85a in pqGetc (result=0xbf3ff81b "@8»Ù@ü\031\216@Dø?¿\035¬Ø@\210", 
conn=0x80d0088) at fe-misc.c:85
#1  0x40d90afe in pqParseInput2 (conn=0x80d0088) at fe-protocol2.c:384
#2  0x40d8ac1d in parseInput (conn=0x80d0088) at fe-exec.c:918
#3  0x40d8ac8f in PQgetResult (conn=0x80d0088) at fe-exec.c:955
#4  0x40d8b0ac in PQexecFinish (conn=0x80d0088) at fe-exec.c:1159
#5  0x40d8aec6 in PQexec (conn=0x80d0088, query=0x80d4270 "set transaction 
isolation level SERIALIZABLE") at fe-exec.c:1047
#6  0x4063aab7 in QPSQLResult::reset(QString const&) (this=0x80d3d20, 
query=@0xbf3ffa9c)
    at sql/drivers/psql/qsql_psql.cpp:473
#7  0x4060dd44 in QSqlQuery::exec(QString const&) (this=0xbf3ffa8c, 
query=@0xbf3ffa9c) at sql/qsqlquery.cpp:358
#8  0x08050411 in PrintEngine::run() (this=0x80a1860) at printengine.cpp:85
#9  0x402b4bf6 in QThreadInstance::start(void*) (_arg=0x80bd4c4) at 
kernel/qthread_unix.cpp:120
#10 0x40b1dc60 in pthread_start_thread () from /lib/libpthread.so.0
Current language:  auto; currently c
(gdb)


#0  0x4061391d in QSqlDatabase::transaction() (this=0x80cc078) at 
sql/qsqldatabase.cpp:760
760         if ( !d->driver->hasFeature( QSqlDriver::Transactions ) )
(gdb) where
#0  0x4061391d in QSqlDatabase::transaction() (this=0x80cc078) at 
sql/qsqldatabase.cpp:760
#1  0x080503db in PrintEngine::run() (this=0x80a70b8) at printengine.cpp:83
#2  0x402b4bf6 in QThreadInstance::start(void*) (_arg=0x80c0c3c) at 
kernel/qthread_unix.cpp:120
#3  0x40b1dc60 in pthread_start_thread () from /lib/libpthread.so.0
(gdb)


#0  0x40d89ea0 in PQclear (res=0x417974dd) at fe-exec.c:349
349
(gdb) where
#0  0x40d89ea0 in PQclear (res=0x417974dd) at fe-exec.c:349
#1  0x40d89f12 in pqClearAsyncResult (conn=0x80cba10) at fe-exec.c:369
#2  0x40d89f7a in pqSaveErrorResult (conn=0x80cba10) at fe-exec.c:397
#3  0x40d8ad11 in PQgetResult (conn=0x80cba10) at fe-exec.c:984
#4  0x40d8b0ac in PQexecFinish (conn=0x80cba10) at fe-exec.c:1159
#5  0x40d8aec6 in PQexec (conn=0x80cba10, query=0x80d8178 "set transaction 
isolation level SERIALIZABLE") at fe-exec.c:1047
#6  0x4063aab7 in QPSQLResult::reset(QString const&) (this=0x80d7f98, 
query=@0xbf3ffa9c)
    at sql/drivers/psql/qsql_psql.cpp:473
#7  0x4060dd44 in QSqlQuery::exec(QString const&) (this=0xbf3ffa8c, 
query=@0xbf3ffa9c) at sql/qsqlquery.cpp:358
#8  0x08050411 in PrintEngine::run() (this=0x80be3b0) at printengine.cpp:85
#9  0x402b4bf6 in QThreadInstance::start(void*) (_arg=0x80c0c44) at 
kernel/qthread_unix.cpp:120
#10 0x40b1dc60 in pthread_start_thread () from /lib/libpthread.so.0
Current language:  auto; currently c
(gdb)




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Multi-threaded user app segfaults when using libpq with separate connections
  2003-08-04 15:29 Multi-threaded user app segfaults when using libpq with separate connections Frank van Vugt <ftm.van.vugt@foxi.nl>
  2003-08-04 15:47 ` Re: Multi-threaded user app segfaults when using libpq with separate connections Tom Lane <tgl@sss.pgh.pa.us>
  2003-08-04 22:34   ` Re: Multi-threaded user app segfaults when using libpq with separate connections Frank van Vugt <ftm.van.vugt@foxi.nl>
@ 2003-08-04 22:41     ` Tom Lane <tgl@sss.pgh.pa.us>
  2003-08-05 21:45       ` Re: Multi-threaded user app segfaults when using libpq with separate connections Frank van Vugt <ftm.van.vugt@foxi.nl>
  0 siblings, 1 reply; 6+ messages in thread

From: Tom Lane @ 2003-08-04 22:41 UTC (permalink / raw)
  To: Frank van Vugt <ftm.van.vugt@foxi.nl>; +Cc: pgsql-interfaces

Frank van Vugt <ftm.van.vugt@foxi.nl> writes:
>> You may care to try your test with CVS tip and see if it works better.

> I've retried this with a cvs-version of this afternoon (local
> time). The build stranded in plpgsql (I seem to need a more recent
> bison), but at that point libpq was already finished. This still
> resulted in more or less the same kind of errors.

Are you sure that each thread is accessing only its own PGconn object?

Other than that, not sure what to suggest.  I get the impression that
something is clobbering memory with abandon.  Do you have any
Purify-like tools to look for memory stomp problems?

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Multi-threaded user app segfaults when using libpq with separate connections
  2003-08-04 15:29 Multi-threaded user app segfaults when using libpq with separate connections Frank van Vugt <ftm.van.vugt@foxi.nl>
  2003-08-04 15:47 ` Re: Multi-threaded user app segfaults when using libpq with separate connections Tom Lane <tgl@sss.pgh.pa.us>
  2003-08-04 22:34   ` Re: Multi-threaded user app segfaults when using libpq with separate connections Frank van Vugt <ftm.van.vugt@foxi.nl>
  2003-08-04 22:41     ` Re: Multi-threaded user app segfaults when using libpq with separate connections Tom Lane <tgl@sss.pgh.pa.us>
@ 2003-08-05 21:45       ` Frank van Vugt <ftm.van.vugt@foxi.nl>
  0 siblings, 0 replies; 6+ messages in thread

From: Frank van Vugt @ 2003-08-05 21:45 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-interfaces

> I get the impression that
> something is clobbering memory with abandon.  Do you have any
> Purify-like tools to look for memory stomp problems?

In addition to my post of this morning containing the regular Valgrind output, 
I'm including here the relevant parts of a valgrind run using the 'helgrind' 
skin, which detects possible data race conditions.


I hope the info is of some use, 

best,





Frank van Vugt

=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=

==14670== 
==14670== Thread 2:
==14670== Possible data race writing variable at 0x43C561A8 
==14670==    at 0x40EB48D7: enlargePQExpBuffer (pqexpbuffer.c:152)
==14670==    by 0x40EB4994: printfPQExpBuffer (pqexpbuffer.c:203)
==14670==    by 0x40EB168B: pqReadData (fe-misc.c:449)
==14670==    by 0x40EAF334: PQgetResult (fe-exec.c:1337)
==14670==   Address 0x43C561A8 is 456 bytes inside a block of size 16384 
alloc'd by thread 3
==14670==    at 0x4001CA2C: malloc (vg_replace_malloc.c:153)
==14670==    by 0x40EABF44: makeEmptyPGconn (fe-connect.c:1881)
==14670==    by 0x40EAA319: PQconnectStart (fe-connect.c:273)
==14670==    by 0x40EAA2D5: PQconnectdb (fe-connect.c:235)
==14670==   Previous state: shared RO, no locks
==14670== 
==14670== Thread 2:
==14670== Possible data race writing variable at 0x43C561B0 
==14670==    at 0x40EB48DF: enlargePQExpBuffer (pqexpbuffer.c:153)
==14670==    by 0x40EB4994: printfPQExpBuffer (pqexpbuffer.c:203)
==14670==    by 0x40EB168B: pqReadData (fe-misc.c:449)
==14670==    by 0x40EAF334: PQgetResult (fe-exec.c:1337)
==14670==   Address 0x43C561B0 is 464 bytes inside a block of size 16384 
alloc'd by thread 3
==14670==    at 0x4001CA2C: malloc (vg_replace_malloc.c:153)
==14670==    by 0x40EABF44: makeEmptyPGconn (fe-connect.c:1881)
==14670==    by 0x40EAA319: PQconnectStart (fe-connect.c:273)
==14670==    by 0x40EAA2D5: PQconnectdb (fe-connect.c:235)
==14670==   Previous state: shared RO, no locks
==14670== 
==14670== Thread 2:
==14670== Possible data race reading variable at 0x40D45614 
==14670==    at 0x4000700D: _dl_lookup_versioned_symbol_internal (in 
/lib/ld-2.3.2.so)
==14670==    by 0x4000AE8E: fixup (in /lib/ld-2.3.2.so)
==14670==    by 0x4000B05F: _dl_runtime_resolve (in /lib/ld-2.3.2.so)
==14670==    by 0x40EB168B: pqReadData (fe-misc.c:449)
==14670==   Address 0x40D45614 is not stack'd, malloc'd or free'd
==14670==   Previous state: shared RW, locked by:0x432F7440
==14670== 
==14670== Thread 2:
==14670== Possible data race writing variable at 0x43C561AC 
==14670==    at 0x40EB497F: printfPQExpBuffer (pqexpbuffer.c:198)
==14670==    by 0x40EB168B: pqReadData (fe-misc.c:449)
==14670==    by 0x40EAF334: PQgetResult (fe-exec.c:1337)
==14670==    by 0x40EAF510: PQexec (fe-exec.c:1441)
==14670==   Address 0x43C561AC is 460 bytes inside a block of size 16384 
alloc'd by thread 3
==14670==    at 0x4001CA2C: malloc (vg_replace_malloc.c:153)
==14670==    by 0x40EABF44: makeEmptyPGconn (fe-connect.c:1881)
==14670==    by 0x40EAA319: PQconnectStart (fe-connect.c:273)
==14670==    by 0x40EAA2D5: PQconnectdb (fe-connect.c:235)
==14670==   Previous state: shared RO, no locks
==14670== 
==14670== Thread 2:
==14670== Possible data race writing variable at 0x43C56198 
==14670==    at 0x40EAE3CC: saveErrorResult (fe-exec.c:632)
==14670==    by 0x40EAF348: PQgetResult (fe-exec.c:1344)
==14670==    by 0x40EAF510: PQexec (fe-exec.c:1441)
==14670==    by 0x407870D2: QPSQLDriver::beginTransaction() 
(sql/drivers/psql/qsql_psql.cpp:698)
==14670==   Address 0x43C56198 is 440 bytes inside a block of size 16384 
alloc'd by thread 3
==14670==    at 0x4001CA2C: malloc (vg_replace_malloc.c:153)
==14670==    by 0x40EABF44: makeEmptyPGconn (fe-connect.c:1881)
==14670==    by 0x40EAA319: PQconnectStart (fe-connect.c:273)
==14670==    by 0x40EAA2D5: PQconnectdb (fe-connect.c:235)
==14670==   Previous state: shared RO, no locks
accessed distinguished 2ndary map! 0x350034
read distinguished 2ndary map! 0x350034
Segmentatie fout (core dumped)




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Fwd: Re: Multi-threaded user app segfaults when using libpq with separate connections
@ 2003-08-05 07:13 Frank van Vugt <ftm.van.vugt@foxi.nl>
  0 siblings, 0 replies; 6+ messages in thread

From: Frank van Vugt @ 2003-08-05 07:13 UTC (permalink / raw)
  To: pgsql-interfaces

> > I've retried this with a cvs-version
> > This still resulted in more or less the same kind of errors.
>
> Are you sure that each thread is accessing only its own PGconn object?

As sure as I can be, yes.

Run by Qt's main event loop, my code simply creates ten objects of a
particular class. The class declares a static mutex, each object starts a
single thread in whose lifetime a new database connection is setup, used and
destroyed again. So this is something simular to the boss/workers design
pattern adapted to Qt's signal/slot mechanism (which explains why I'm using a
class object per additional thread).

Looking at Qt's code it seems inevitable that a separate PGconn object is
 used for each and every connection made. I've taken this problem up with
 TrollTech first, they are pretty sure it's not caused by their libs.

> Other than that, not sure what to suggest.  I get the impression that
> something is clobbering memory with abandon.  Do you have any
> Purify-like tools to look for memory stomp problems?

I know TrollTech is using Purify, I have Valgrind available. You'll find the
output of a run with the option '--trace-pthread=some' attached.

FYI, QSqlDatabase::commit() (sql/qsqldatabase.cpp:775) contains:
	if ( !d->driver->hasFeature( QSqlDriver::Transactions ) )
		return FALSE;
The parameter is an enum, inside QSqlDriver (the one specific to PostgreSQL),
this resolves into a plain:
	bool QPSQLDriver::hasFeature( DriverFeature f ) const
	{
	    switch ( f ) {
	    case Transactions:
	        return TRUE;
	    case QuerySize:
	        return TRUE;
	    case BLOB:
	        return pro >= QPSQLDriver::Version71;
	    case Unicode:
	        return d->isUtf8;
	    default:
	        return FALSE;
	    }
	}



Best,




Frank.

=+=+=+=+=+=+=+=+=+=+=+=+=

==2028== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux.
==2028== Copyright (C) 2002, and GNU GPL'd, by Julian Seward.
==2028== Using valgrind-1.9.5pre, a program instrumentation system for
x86-linux.
==2028== Copyright (C) 2000-2002, and GNU GPL'd, by Julian Seward.
==2028== Estimated CPU clock rate is 501 MHz
==2028== For more details, rerun with: -v
==2028==
--2028-- PTHREAD[1]: pthread_key_create      *key 0x41107D40, destr
 0x41106480 --2028-- PTHREAD[1]: pthread_getspecific_ptr
--2028-- PTHREAD[1]: pthread_setspecific_ptr  ptr 0x4378C024

--2028-- PTHREAD[1]: pthread_getspecific_ptr
 *** DELETED MULTIPLE REPETITIONS OF THE SAME MESSAGE

--2028-- PTHREAD[1]: pthread_key_validate    key 0x0
--2028-- PTHREAD[1]: pthread_getspecific_ptr
 *** DELETED MULTIPLE REPETITIONS OF THE SAME MESSAGE (SET)

==2028== Syscall param modify_ldt(ptr)(func=1 or 0x11) contains uninitialised
or unaddressable byte(s)
==2028==    at 0x40FFD898: (within /usr/lib/libGL.so.1.0.4363)
==2028==    Address 0xBFFFF120 is on thread 1's stack
--2028-- PTHREAD[1]: pthread_key_create      *key 0x4102C2A0, destr
 0x40FFDC64

--2028-- PTHREAD[1]: pthread_getspecific_ptr
 *** DELETED MULTIPLE REPETITIONS OF THE SAME MESSAGE (SET)

--2028-- PTHREAD[1]: pthread_key_validate    key 0x1
--2028-- PTHREAD[1]: pthread_getspecific_ptr
--2028-- PTHREAD[1]: pthread_key_create      *key 0x40C16DA0, destr 0x0

--2028-- PTHREAD[1]: pthread_getspecific_ptr
 *** DELETED MULTIPLE REPETITIONS OF THE SAME MESSAGE (SET)

--2028-- PTHREAD[1]: pthread_key_validate    key 0x2
--2028-- PTHREAD[1]: pthread_getspecific_ptr
- *** DELETED MULTIPLE REPETITIONS OF THE SAME MESSAGE (SET)

==2028==
==2028== Conditional jump or move depends on uninitialised value(s)
==2028==    at 0x40010847: strlen (in /lib/ld-2.3.2.so)
==2028==    by 0x4000B312: _dl_signal_cerror (in /lib/ld-2.3.2.so)
==2028==    by 0x40006BBE: _dl_lookup_symbol_internal (in /lib/ld-2.3.2.so)
==2028==    by 0x40F234F9: do_dlsym (in /lib/libc.so.6)
--2028-- PTHREAD[1]: pthread_key_validate    key 0x0
--2028-- PTHREAD[1]: pthread_getspecific_ptr
--2028-- PTHREAD[1]: pthread_key_validate    key 0x0
--2028-- PTHREAD[1]: pthread_getspecific_ptr
==2028==
==2028== Syscall param write(buf) contains uninitialised or unaddressable
byte(s)
==2028==    at 0x40EE63A8: __GI___libc_write (in /lib/libc.so.6)
==2028==    by 0x40C91EBD: _X11TransSocketWrite (in
/usr/X11R6/lib/libX11.so.6.2)
==2028==    by 0x40C92AFE: _X11TransWrite (in /usr/X11R6/lib/libX11.so.6.2)
==2028==    by 0x40C71663: _XFlushInt (in /usr/X11R6/lib/libX11.so.6.2)
==2028==    Address 0x4385DC24 is 116 bytes inside a block of size 2048
alloc'd
==2028==    at 0x401633BB: calloc (in /usr/lib/valgrind/valgrind.so)
==2028==    by 0x40C62736: XOpenDisplay (in /usr/X11R6/lib/libX11.so.6.2)
==2028==    by 0x4042FB87: qt_init_internal(int*, char**, _XDisplay*,
 unsigned long, unsigned long) (kernel/qapplication_x11.cpp:1657)
==2028==    by 0x40431AC6: qt_init(int*, char**, QApplication::Type)
(kernel/qapplication_x11.cpp:2315)

--2028-- PTHREAD[1]: pthread_key_validate    key 0x2
--2028-- PTHREAD[1]: pthread_getspecific_ptr
 *** DELETED MULTIPLE REPETITIONS OF THE SAME MESSAGE (SET)

initial print engine constructor reached
==2028== valgrind's libpthread.so: IGNORED call to:
pthread_attr_setinheritsched
--2028-- PTHREAD[1]: pthread_key_create      *key 0xBFFFEF68, destr 0x0

--2028-- PTHREAD[1]: pthread_getspecific_ptr
 *** DELETED MULTIPLE REPETITIONS OF THE SAME MESSAGE (SET)

--2028-- PTHREAD[1]: pthread_key_create      *key 0xBFFFEF68, destr 0x0

--2028-- PTHREAD[1]: pthread_getspecific_ptr
 *** DELETED MULTIPLE REPETITIONS OF THE SAME MESSAGE (SET)

--2028-- PTHREAD[1]: pthread_key_create      *key 0xBFFFEF68, destr 0x0

--2028-- PTHREAD[1]: pthread_getspecific_ptr
 *** DELETED MULTIPLE REPETITIONS OF THE SAME MESSAGE (SET)

--2028-- PTHREAD[1]: pthread_key_create      *key 0xBFFFEF68, destr 0x0

--2028-- PTHREAD[1]: pthread_getspecific_ptr
 *** DELETED MULTIPLE REPETITIONS OF THE SAME MESSAGE (SET)

--2028-- PTHREAD[1]: pthread_key_create      *key 0xBFFFEF68, destr 0x0

--2028-- PTHREAD[1]: pthread_getspecific_ptr
 *** DELETED MULTIPLE REPETITIONS OF THE SAME MESSAGE (SET)

--2028-- PTHREAD[1]: pthread_key_create      *key 0xBFFFEF68, destr 0x0

--2028-- PTHREAD[1]: pthread_getspecific_ptr
 *** DELETED MULTIPLE REPETITIONS OF THE SAME MESSAGE (SET)

--2028-- PTHREAD[1]: pthread_key_create      *key 0xBFFFEF68, destr 0x0

--2028-- PTHREAD[1]: pthread_getspecific_ptr
 *** DELETED MULTIPLE REPETITIONS OF THE SAME MESSAGE (SET)

==2028== valgrind's libpthread.so: IGNORED call to: pthread_attr_destroy
--2028-- PTHREAD[2]: pthread_key_validate    key 0x2
--2028-- PTHREAD[2]: pthread_getspecific_ptr
--2028-- PTHREAD[2]: pthread_setspecific_ptr  ptr 0x443F7BA0
print thread run() reached, thread halted
--2028-- PTHREAD[2]: pthread_cond_wait        cv 0x4382FC18, mx 0x45113E10:
BLOCK
==2028==
==2028== Syscall param write(buf) contains uninitialised or unaddressable
byte(s)
==2028==    at 0x40EE63A8: __GI___libc_write (in /lib/libc.so.6)
==2028==    by 0x410FDD9D: _IceTransSocketWrite (in
/usr/X11R6/lib/libICE.so.6.3)
==2028==    by 0x410FEB6E: _IceTransWrite (in /usr/X11R6/lib/libICE.so.6.3)
==2028==    by 0x410F554A: _IceWrite (in /usr/X11R6/lib/libICE.so.6.3)
==2028==    Address 0x438739E8 is 12 bytes inside a block of size 1024
 alloc'd ==2028==    at 0x401633BB: calloc (in /usr/lib/valgrind/valgrind.so)
 ==2028==    by 0x410F24A6: IceOpenConnection (in
 /usr/X11R6/lib/libICE.so.6.3) ==2028==    by 0x410E73A0: SmcOpenConnection
 (in /usr/X11R6/lib/libSM.so.6.0) ==2028==    by 0x4043AF43:
 QSessionManager::QSessionManager(QApplication*, QString&, QString&)
 (kernel/qapplication_x11.cpp:6183)
--2028-- PTHREAD[2]: pthread_cond_signal      cv 0x4382FC18: RESUME with mx
0x45113E10
new print engine created
==2028== valgrind's libpthread.so: IGNORED call to:
pthread_attr_setinheritsched
==2028== valgrind's libpthread.so: IGNORED call to: pthread_attr_destroy
new print engine created
==2028== valgrind's libpthread.so: IGNORED call to:
pthread_attr_setinheritsched
==2028== valgrind's libpthread.so: IGNORED call to: pthread_attr_destroy
print thread continued
trying to lock my_active in order to add/open a database
my_active has been locked in order to add/open database connection
(08:04:27.670)
==2028==
==2028== Thread 2:
==2028== Conditional jump or move depends on uninitialised value(s)
==2028==    at 0x40010606: strchr (in /lib/ld-2.3.2.so)
--2028-- PTHREAD[3]: pthread_mutex_lock       mx 0x40D15688: BLOCK
--2028-- PTHREAD[4]: pthread_mutex_lock       mx 0x40D15688: BLOCK
new print engine created
new print engine created
new print engine created
new print engine created
new print engine created
new print engine created
new print engine created
--2028-- PTHREAD[3]: pthread_mutex_lock       mx 0x40D15688: RESUME
--2028-- PTHREAD[4]: pthread_mutex_lock       mx 0x40D15688: RESUME
--2028-- PTHREAD[3]: pthread_key_validate    key 0x2
--2028-- PTHREAD[3]: pthread_getspecific_ptr
--2028-- PTHREAD[3]: pthread_setspecific_ptr  ptr 0x443C6A78
print thread run() reached, thread halted
--2028-- PTHREAD[3]: pthread_cond_wait        cv 0x4382FC18, mx 0x45433E10:
BLOCK
--2028-- PTHREAD[4]: pthread_key_validate    key 0x2
--2028-- PTHREAD[4]: pthread_getspecific_ptr
--2028-- PTHREAD[4]: pthread_setspecific_ptr  ptr 0x443C36F4
print thread run() reached, thread halted
--2028-- PTHREAD[4]: pthread_cond_wait        cv 0x4382FC18, mx 0x45665E10:
BLOCK
--2028-- PTHREAD[5]: pthread_key_validate    key 0x2
--2028-- PTHREAD[5]: pthread_getspecific_ptr
--2028-- PTHREAD[5]: pthread_setspecific_ptr  ptr 0x443C6B70
print thread run() reached, thread halted
--2028-- PTHREAD[5]: pthread_cond_wait        cv 0x4382FC18, mx 0x458FBE10:
BLOCK
--2028-- PTHREAD[6]: pthread_key_validate    key 0x2
--2028-- PTHREAD[6]: pthread_getspecific_ptr
--2028-- PTHREAD[6]: pthread_setspecific_ptr  ptr 0x443C37EC
print thread run() reached, thread halted
--2028-- PTHREAD[6]: pthread_cond_wait        cv 0x4382FC18, mx 0x45B1BE10:
BLOCK
--2028-- PTHREAD[7]: pthread_key_validate    key 0x2
--2028-- PTHREAD[7]: pthread_getspecific_ptr
--2028-- PTHREAD[7]: pthread_setspecific_ptr  ptr 0x443C6C68
print thread run() reached, thread halted
--2028-- PTHREAD[7]: pthread_cond_wait        cv 0x4382FC18, mx 0x45D4DE10:
BLOCK
--2028-- PTHREAD[8]: pthread_key_validate    key 0x2
--2028-- PTHREAD[8]: pthread_getspecific_ptr
--2028-- PTHREAD[8]: pthread_setspecific_ptr  ptr 0x443C38E4
print thread run() reached, thread halted
--2028-- PTHREAD[8]: pthread_cond_wait        cv 0x4382FC18, mx 0x45F7FE10:
BLOCK
--2028-- PTHREAD[9]: pthread_key_validate    key 0x2
--2028-- PTHREAD[9]: pthread_getspecific_ptr
--2028-- PTHREAD[9]: pthread_setspecific_ptr  ptr 0x443C6D60
print thread run() reached, thread halted
--2028-- PTHREAD[9]: pthread_cond_wait        cv 0x4382FC18, mx 0x4619FE10:
BLOCK
--2028-- PTHREAD[10]: pthread_key_validate    key 0x2
--2028-- PTHREAD[10]: pthread_getspecific_ptr
--2028-- PTHREAD[10]: pthread_setspecific_ptr  ptr 0x443C39DC
print thread run() reached, thread halted
--2028-- PTHREAD[10]: pthread_cond_wait        cv 0x4382FC18, mx 0x464BFE10:
BLOCK
--2028-- PTHREAD[3]: pthread_cond_signal      cv 0x4382FC18: RESUME with mx
0x45433E10
new print engine created
--2028-- PTHREAD[4]: pthread_cond_signal      cv 0x4382FC18: RESUME with mx
0x45665E10
new print engine created
--2028-- PTHREAD[5]: pthread_cond_signal      cv 0x4382FC18: RESUME with mx
0x458FBE10
new print engine created
--2028-- PTHREAD[6]: pthread_cond_signal      cv 0x4382FC18: RESUME with mx
0x45B1BE10
new print engine created
--2028-- PTHREAD[7]: pthread_cond_signal      cv 0x4382FC18: RESUME with mx
0x45D4DE10
new print engine created
--2028-- PTHREAD[2]: pthread_key_validate    key 0x2
--2028-- PTHREAD[2]: pthread_getspecific_ptr
--2028-- PTHREAD[2]: pthread_key_validate    key 0x2
--2028-- PTHREAD[2]: pthread_getspecific_ptr
print thread continued
trying to lock my_active in order to add/open a database
--2028-- PTHREAD[3]: pthread_mutex_lock       mx 0x4382FB94: BLOCK
print thread continued
trying to lock my_active in order to add/open a database
--2028-- PTHREAD[4]: pthread_mutex_lock       mx 0x4382FB94: BLOCK
print thread continued
trying to lock my_active in order to add/open a database
--2028-- PTHREAD[5]: pthread_mutex_lock       mx 0x4382FB94: BLOCK
print thread continued
trying to lock my_active in order to add/open a database
--2028-- PTHREAD[6]: pthread_mutex_lock       mx 0x4382FB94: BLOCK
print thread continued
trying to lock my_active in order to add/open a database
--2028-- PTHREAD[7]: pthread_mutex_lock       mx 0x4382FB94: BLOCK
--2028-- PTHREAD[11]: pthread_key_validate    key 0x2
--2028-- PTHREAD[11]: pthread_getspecific_ptr
--2028-- PTHREAD[11]: pthread_setspecific_ptr  ptr 0x443CDBC8
print thread run() reached, thread halted
--2028-- PTHREAD[11]: pthread_cond_wait        cv 0x4382FC18, mx 0x4672CE10:
BLOCK
--2028-- PTHREAD[12]: pthread_key_validate    key 0x2
--2028-- PTHREAD[12]: pthread_getspecific_ptr
--2028-- PTHREAD[12]: pthread_setspecific_ptr  ptr 0x443CFEE4
print thread run() reached, thread halted
--2028-- PTHREAD[12]: pthread_cond_wait        cv 0x4382FC18, mx 0x4694CE10:
BLOCK
--2028-- PTHREAD[13]: pthread_key_validate    key 0x2
--2028-- PTHREAD[13]: pthread_getspecific_ptr
--2028-- PTHREAD[13]: pthread_setspecific_ptr  ptr 0x443CDCC0
print thread run() reached, thread halted
--2028-- PTHREAD[13]: pthread_cond_wait        cv 0x4382FC18, mx 0x46B7EE10:
BLOCK
--2028-- PTHREAD[14]: pthread_key_validate    key 0x2
--2028-- PTHREAD[14]: pthread_getspecific_ptr
--2028-- PTHREAD[14]: pthread_setspecific_ptr  ptr 0x443CFFDC
print thread run() reached, thread halted
--2028-- PTHREAD[14]: pthread_cond_wait        cv 0x4382FC18, mx 0x46DB0E10:
BLOCK
--2028-- PTHREAD[15]: pthread_key_validate    key 0x2
--2028-- PTHREAD[15]: pthread_getspecific_ptr
--2028-- PTHREAD[15]: pthread_setspecific_ptr  ptr 0x443CDDB8
print thread run() reached, thread halted
--2028-- PTHREAD[15]: pthread_cond_wait        cv 0x4382FC18, mx 0x46FE2E10:
BLOCK
--2028-- PTHREAD[16]: pthread_key_validate    key 0x2
--2028-- PTHREAD[16]: pthread_getspecific_ptr
--2028-- PTHREAD[16]: pthread_setspecific_ptr  ptr 0x443D00D4
print thread run() reached, thread halted
--2028-- PTHREAD[16]: pthread_cond_wait        cv 0x4382FC18, mx 0x47214E10:
BLOCK
--2028-- PTHREAD[2]: pthread_key_validate    key 0x2
--2028-- PTHREAD[2]: pthread_getspecific_ptr
--2028-- PTHREAD[2]: pthread_key_validate    key 0x2
--2028-- PTHREAD[2]: pthread_getspecific_ptr
trying to unlock my_active since we now have added/opened a database
--2028-- PTHREAD[3]: pthread_mutex_lock       mx 0x4382FB94: RESUME
my_active has been locked after opening database connection (08:08:26.717)
--2028-- PTHREAD[2]: pthread_mutex_lock       mx 0x441C8ADC: BLOCK
my_active has been locked in order to add/open database connection
(08:08:26.810)
--2028-- PTHREAD[3]: pthread_mutex_lock       mx 0x441C8ADC: BLOCK
--2028-- PTHREAD[2]: pthread_mutex_lock       mx 0x441C8ADC: RESUME
--2028-- PTHREAD[1]: pthread_mutex_lock       mx 0x441C8ADC: BLOCK
--2028-- PTHREAD[1]: pthread_mutex_lock       mx 0x441C8ADC: RESUME
--2028-- PTHREAD[2]: pthread_key_validate    key 0x2
--2028-- PTHREAD[2]: pthread_getspecific_ptr
--2028-- PTHREAD[3]: pthread_mutex_lock       mx 0x441C8ADC: RESUME
--2028-- PTHREAD[1]: pthread_mutex_lock       mx 0x441C8ADC: BLOCK
--2028-- PTHREAD[1]: pthread_mutex_lock       mx 0x441C8ADC: RESUME
--2028-- PTHREAD[3]: pthread_mutex_lock       mx 0x441C8ADC: BLOCK
--2028-- PTHREAD[3]: pthread_mutex_lock       mx 0x441C8ADC: RESUME
--2028-- PTHREAD[1]: pthread_mutex_lock       mx 0x441C8ADC: BLOCK
--2028-- PTHREAD[2]: pthread_key_validate    key 0x2
--2028-- PTHREAD[2]: pthread_getspecific_ptr
--2028-- PTHREAD[1]: pthread_mutex_lock       mx 0x441C8ADC: RESUME
--2028-- PTHREAD[3]: pthread_key_validate    key 0x2
--2028-- PTHREAD[3]: pthread_getspecific_ptr
--2028-- PTHREAD[3]: pthread_key_validate    key 0x2
--2028-- PTHREAD[3]: pthread_getspecific_ptr
==2028==
==2028== Thread 2:
==2028== Invalid read of size 4
==2028==    at 0x4080597A: QSqlDatabase::commit() (sql/qsqldatabase.cpp:775)
==2028==    by 0x8050BAC: PrintEngine::run() (printengine.cpp:118)
==2028==    by 0x404A6BF5: QThreadInstance::start(void*)
(kernel/qthread_unix.cpp:120)
==2028==    by 0x40D0E5C8: thread_wrapper (in
 /usr/lib/valgrind/libpthread.so) ==2028==    Address 0x443F8E8C is 40 bytes
 inside a block of size 44 free'd ==2028==    at 0x40163266: __builtin_delete
 (in /usr/lib/valgrind/valgrind.so) ==2028==    by 0x40163284: operator
 delete(void*) (in
/usr/lib/valgrind/valgrind.so)
==2028==    by 0x408056A1: QSqlDatabase::~QSqlDatabase()
(sql/qsqldatabase.cpp:674)
==2028==    by 0x40806D8C: QDict<QSqlDatabase>::deleteItem(void*)
(../include/qdict.h:97)
==2028==
==2028== Thread 2:
==2028== Invalid read of size 4
==2028==    at 0x4080597D: QSqlDatabase::commit() (sql/qsqldatabase.cpp:775)
==2028==    by 0x8050BAC: PrintEngine::run() (printengine.cpp:118)
==2028==    by 0x404A6BF5: QThreadInstance::start(void*)
(kernel/qthread_unix.cpp:120)
==2028==    by 0x40D0E5C8: thread_wrapper (in
 /usr/lib/valgrind/libpthread.so) ==2028==    Address 0x443F8EFC is 0 bytes
 inside a block of size 36 free'd ==2028==    at 0x40163266: __builtin_delete
 (in /usr/lib/valgrind/valgrind.so) ==2028==    by 0x40163284: operator
 delete(void*) (in
/usr/lib/valgrind/valgrind.so)
==2028==    by 0x40805655: QSqlDatabase::~QSqlDatabase()
(sql/qsqldatabase.cpp:660)
==2028==    by 0x40806D8C: QDict<QSqlDatabase>::deleteItem(void*)
(../include/qdict.h:97)
==2028==
==2028== Thread 2:
==2028== Invalid read of size 4
==2028==    at 0x4080597F: QSqlDatabase::commit() (sql/qsqldatabase.cpp:775)
==2028==    by 0x8050BAC: PrintEngine::run() (printengine.cpp:118)
==2028==    by 0x404A6BF5: QThreadInstance::start(void*)
(kernel/qthread_unix.cpp:120)
==2028==    by 0x40D0E5C8: thread_wrapper (in
 /usr/lib/valgrind/libpthread.so) ==2028==    Address 0x443F8F50 is 0 bytes
 inside a block of size 72 free'd ==2028==    at 0x40163266: __builtin_delete
 (in /usr/lib/valgrind/valgrind.so) ==2028==    by 0x40163284: operator
 delete(void*) (in
/usr/lib/valgrind/valgrind.so)
==2028==    by 0x4082D983: QPSQLDriver::~QPSQLDriver()
(sql/drivers/psql/qsql_psql.cpp:600)
==2028==    by 0x408055FC: QSqlDatabase::~QSqlDatabase()
(sql/qsqldatabase.cpp:656)
==2028==
==2028== Thread 2:
==2028== Invalid read of size 4
==2028==    at 0x40805989: QSqlDatabase::commit() (sql/qsqldatabase.cpp:775)
==2028==    by 0x8050BAC: PrintEngine::run() (printengine.cpp:118)
==2028==    by 0x404A6BF5: QThreadInstance::start(void*)
(kernel/qthread_unix.cpp:120)
==2028==    by 0x40D0E5C8: thread_wrapper (in
 /usr/lib/valgrind/libpthread.so) ==2028==    Address 0x443F8E8C is 40 bytes
 inside a block of size 44 free'd ==2028==    at 0x40163266: __builtin_delete
 (in /usr/lib/valgrind/valgrind.so) ==2028==    by 0x40163284: operator
 delete(void*) (in
/usr/lib/valgrind/valgrind.so)
==2028==    by 0x408056A1: QSqlDatabase::~QSqlDatabase()
(sql/qsqldatabase.cpp:674)
==2028==    by 0x40806D8C: QDict<QSqlDatabase>::deleteItem(void*)
(../include/qdict.h:97)
==2028==
==2028== Thread 2:
==2028== Invalid read of size 4
==2028==    at 0x4080598C: QSqlDatabase::commit() (sql/qsqldatabase.cpp:775)
==2028==    by 0x8050BAC: PrintEngine::run() (printengine.cpp:118)
==2028==    by 0x404A6BF5: QThreadInstance::start(void*)
(kernel/qthread_unix.cpp:120)
==2028==    by 0x40D0E5C8: thread_wrapper (in
 /usr/lib/valgrind/libpthread.so) ==2028==    Address 0x443F8EFC is 0 bytes
 inside a block of size 36 free'd ==2028==    at 0x40163266: __builtin_delete
 (in /usr/lib/valgrind/valgrind.so) ==2028==    by 0x40163284: operator
 delete(void*) (in
/usr/lib/valgrind/valgrind.so)
==2028==    by 0x40805655: QSqlDatabase::~QSqlDatabase()
(sql/qsqldatabase.cpp:660)
==2028==    by 0x40806D8C: QDict<QSqlDatabase>::deleteItem(void*)
(../include/qdict.h:97)
disInstr: unhandled opcode 0x6E then 0xCD

valgrind: the `impossible' happened:
   unhandled x86 opcode
Basic block ctr is approximately 22650000

sched status:

Thread 1: status = Runnable, associated_mx = 0x0, associated_cv = 0x0
==2028==    at 0x40007BB0: do_lookup (in /lib/ld-2.3.2.so)
==2028==    by 0x400069E2: _dl_lookup_symbol_internal (in /lib/ld-2.3.2.so)
==2028==    by 0x4000AE30: fixup (in /lib/ld-2.3.2.so)
==2028==    by 0x4000B05F: _dl_runtime_resolve (in /lib/ld-2.3.2.so)

Thread 2: status = Runnable, associated_mx = 0x0, associated_cv = 0x0
==2028==    at 0x40ADAF78: ???
==2028==    by 0x8050BAC: PrintEngine::run() (printengine.cpp:118)
==2028==    by 0x404A6BF5: QThreadInstance::start(void*)
(kernel/qthread_unix.cpp:120)
==2028==    by 0x40D0E5C8: thread_wrapper (in
 /usr/lib/valgrind/libpthread.so)

Thread 3: status = Runnable, associated_mx = 0x0, associated_cv = 0x0
==2028==    at 0x4043C542: QGArray::at(unsigned) const
(../include/qgarray.h:120)
==2028==    by 0x4090262B: QRegExpEngine::heuristicallyChooseHeuristic()
(tools/qregexp.cpp:1495)
==2028==    by 0x40906573: QRegExpEngine::Box::setupHeuristics()
(tools/qregexp.cpp:2545)
==2028==    by 0x40907832: QRegExpEngine::parse(QChar const*, int)
(tools/qregexp.cpp:2940)

Thread 4: status = WaitMX, associated_mx = 0x4382FB94, associated_cv = 0x0
==2028==    at 0x40D0EB94: __pthread_mutex_lock (in
/usr/lib/valgrind/libpthread.so)
==2028==    by 0x408D3D29: QRealMutexPrivate::lock()
(tools/qmutex_unix.cpp:142)
==2028==    by 0x408D4963: QMutex::lock() (tools/qmutex_unix.cpp:464)
==2028==    by 0x804FD9E: PrintEngine::run() (printengine.cpp:56)

Thread 5: status = WaitMX, associated_mx = 0x4382FB94, associated_cv = 0x0
==2028==    at 0x40D0EB94: __pthread_mutex_lock (in
/usr/lib/valgrind/libpthread.so)
==2028==    by 0x408D3D29: QRealMutexPrivate::lock()
(tools/qmutex_unix.cpp:142)
==2028==    by 0x408D4963: QMutex::lock() (tools/qmutex_unix.cpp:464)
==2028==    by 0x804FD9E: PrintEngine::run() (printengine.cpp:56)

Thread 6: status = WaitMX, associated_mx = 0x4382FB94, associated_cv = 0x0
==2028==    at 0x40D0EB94: __pthread_mutex_lock (in
/usr/lib/valgrind/libpthread.so)
==2028==    by 0x408D3D29: QRealMutexPrivate::lock()
(tools/qmutex_unix.cpp:142)
==2028==    by 0x408D4963: QMutex::lock() (tools/qmutex_unix.cpp:464)
==2028==    by 0x804FD9E: PrintEngine::run() (printengine.cpp:56)

Thread 7: status = WaitMX, associated_mx = 0x4382FB94, associated_cv = 0x0
==2028==    at 0x40D0EB94: __pthread_mutex_lock (in
/usr/lib/valgrind/libpthread.so)
==2028==    by 0x408D3D29: QRealMutexPrivate::lock()
(tools/qmutex_unix.cpp:142)
==2028==    by 0x408D4963: QMutex::lock() (tools/qmutex_unix.cpp:464)
==2028==    by 0x804FD9E: PrintEngine::run() (printengine.cpp:56)

Thread 8: status = WaitCV, associated_mx = 0x45F7FE10, associated_cv =
0x4382FC18
==2028==    at 0x40D0EE6A: pthread_cond_wait (in
/usr/lib/valgrind/libpthread.so)
==2028==    by 0x408D5C79: QWaitCondition::wait(unsigned long)
(tools/qwaitcondition_unix.cpp:243)
==2028==    by 0x804FD6D: PrintEngine::run() (printengine.cpp:51)
==2028==    by 0x404A6BF5: QThreadInstance::start(void*)
(kernel/qthread_unix.cpp:120)

Thread 9: status = WaitCV, associated_mx = 0x4619FE10, associated_cv =
0x4382FC18
==2028==    at 0x40D0EE6A: pthread_cond_wait (in
/usr/lib/valgrind/libpthread.so)
==2028==    by 0x408D5C79: QWaitCondition::wait(unsigned long)
(tools/qwaitcondition_unix.cpp:243)
==2028==    by 0x804FD6D: PrintEngine::run() (printengine.cpp:51)
==2028==    by 0x404A6BF5: QThreadInstance::start(void*)
(kernel/qthread_unix.cpp:120)

Thread 10: status = WaitCV, associated_mx = 0x464BFE10, associated_cv =
0x4382FC18
==2028==    at 0x40D0EE6A: pthread_cond_wait (in
/usr/lib/valgrind/libpthread.so)
==2028==    by 0x408D5C79: QWaitCondition::wait(unsigned long)
(tools/qwaitcondition_unix.cpp:243)
==2028==    by 0x804FD6D: PrintEngine::run() (printengine.cpp:51)
==2028==    by 0x404A6BF5: QThreadInstance::start(void*)
(kernel/qthread_unix.cpp:120)

Thread 11: status = WaitCV, associated_mx = 0x4672CE10, associated_cv =
0x4382FC18
==2028==    at 0x40D0EE6A: pthread_cond_wait (in
/usr/lib/valgrind/libpthread.so)
==2028==    by 0x408D5C79: QWaitCondition::wait(unsigned long)
(tools/qwaitcondition_unix.cpp:243)
==2028==    by 0x804FD6D: PrintEngine::run() (printengine.cpp:51)
==2028==    by 0x404A6BF5: QThreadInstance::start(void*)
(kernel/qthread_unix.cpp:120)

Thread 12: status = WaitCV, associated_mx = 0x4694CE10, associated_cv =
0x4382FC18
==2028==    at 0x40D0EE6A: pthread_cond_wait (in
/usr/lib/valgrind/libpthread.so)
==2028==    by 0x408D5C79: QWaitCondition::wait(unsigned long)
(tools/qwaitcondition_unix.cpp:243)
==2028==    by 0x804FD6D: PrintEngine::run() (printengine.cpp:51)
==2028==    by 0x404A6BF5: QThreadInstance::start(void*)
(kernel/qthread_unix.cpp:120)

Thread 13: status = WaitCV, associated_mx = 0x46B7EE10, associated_cv =
0x4382FC18
==2028==    at 0x40D0EE6A: pthread_cond_wait (in
/usr/lib/valgrind/libpthread.so)
==2028==    by 0x408D5C79: QWaitCondition::wait(unsigned long)
(tools/qwaitcondition_unix.cpp:243)
==2028==    by 0x804FD6D: PrintEngine::run() (printengine.cpp:51)
==2028==    by 0x404A6BF5: QThreadInstance::start(void*)
(kernel/qthread_unix.cpp:120)

Thread 14: status = WaitCV, associated_mx = 0x46DB0E10, associated_cv =
0x4382FC18
==2028==    at 0x40D0EE6A: pthread_cond_wait (in
/usr/lib/valgrind/libpthread.so)
==2028==    by 0x408D5C79: QWaitCondition::wait(unsigned long)
(tools/qwaitcondition_unix.cpp:243)
==2028==    by 0x804FD6D: PrintEngine::run() (printengine.cpp:51)
==2028==    by 0x404A6BF5: QThreadInstance::start(void*)
(kernel/qthread_unix.cpp:120)

Thread 15: status = WaitCV, associated_mx = 0x46FE2E10, associated_cv =
0x4382FC18
==2028==    at 0x40D0EE6A: pthread_cond_wait (in
/usr/lib/valgrind/libpthread.so)
==2028==    by 0x408D5C79: QWaitCondition::wait(unsigned long)
(tools/qwaitcondition_unix.cpp:243)
==2028==    by 0x804FD6D: PrintEngine::run() (printengine.cpp:51)
==2028==    by 0x404A6BF5: QThreadInstance::start(void*)
(kernel/qthread_unix.cpp:120)

Thread 16: status = WaitCV, associated_mx = 0x47214E10, associated_cv =
0x4382FC18
==2028==    at 0x40D0EE6A: pthread_cond_wait (in
/usr/lib/valgrind/libpthread.so)
==2028==    by 0x408D5C79: QWaitCondition::wait(unsigned long)
(tools/qwaitcondition_unix.cpp:243)
==2028==    by 0x804FD6D: PrintEngine::run() (printengine.cpp:51)
==2028==    by 0x404A6BF5: QThreadInstance::start(void*)
(kernel/qthread_unix.cpp:120)

Please report this bug to: jseward@acm.org

-------------------------------------------------------

-- 
MvG,




Frank.




^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2003-08-05 21:45 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-08-04 15:29 Multi-threaded user app segfaults when using libpq with separate connections Frank van Vugt <ftm.van.vugt@foxi.nl>
2003-08-04 15:47 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-08-04 22:34   ` Frank van Vugt <ftm.van.vugt@foxi.nl>
2003-08-04 22:41     ` Tom Lane <tgl@sss.pgh.pa.us>
2003-08-05 21:45       ` Frank van Vugt <ftm.van.vugt@foxi.nl>
2003-08-05 07:13 Fwd: Re: Multi-threaded user app segfaults when using libpq with separate connections Frank van Vugt <ftm.van.vugt@foxi.nl>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox