Thread: PQmakeEmptyPQresult makes my application dumps core?
Adam PAPAI wooh (at) wooh (dot) hu System Configuration --------------------- Architecture: Intel(R) Xeon(TM) CPU 2.80GHz Operating System: Debian/GNU Linux i686 GNU/Linux PostgreSQL version: (PostgreSQL) 7.4.7 Compiler used: gcc 3.3.6 Problem description --------------------- Usually our program dumps core several times a day, but the reason is unknown. All I know from the core file is the lines below. during PQexec(db->conn, query) it dumps core. Should it happen due to a connection problem between the pgsql server and our program? What could be the resolution to avoid the coredumps? (gdb) up #1 0xb7df4cff in malloc () from /lib/tls/libc.so.6 (gdb) up #2 0xb7eed753 in PQmakeEmptyPGresult () from /usr/lib/libpq.so.3 (gdb) up #3 0xb7ef5818 in pqParseInput3 () from /usr/lib/libpq.so.3 (gdb) up #4 0xb7ef566f in pqParseInput3 () from /usr/lib/libpq.so.3 (gdb) up #5 0xb7eee8e9 in PQconsumeInput () from /usr/lib/libpq.so.3 (gdb) up #6 0xb7eeea71 in PQgetResult () from /usr/lib/libpq.so.3 (gdb) up #7 0xb7eeed3b in PQexecPrepared () from /usr/lib/libpq.so.3 (gdb) up #8 0x080515ad in db_try_exec (query=0x8076468 "SELECT last_value FROM alarm_alarm_id_seq", ntry=2) at ../db/db.c:31 31 res = PQexec(db->conn, query); -- Adam PAPAI D i g i t a l Influence http://www.digitalinfluence.hu E-mail: wooh@wooh.hu Phone: +36 30 33-55-735 (Hungary)
Adam PAPAI <wooh@wooh.hu> writes: > Usually our program dumps core several times a day, but the reason is > unknown. All I know from the core file is the lines below. That failure is inside malloc, not PQmakeEmptyPQresult, and the odds are extremely high that the reason is some part of your program clobbering memory that doesn't belong to it (and thereby damaging malloc's internal data structures). Try running your program under Electric Fence or some other debugging malloc package. regards, tom lane
"Adam PAPAI" <wooh@wooh.hu> writes: > PostgreSQL version: (PostgreSQL) 7.4.7 Incidentally there have been 11 bug-fix releases to 7.4 since this one. Several of those cause crashes or data corruption and you would be well-advised to install 7.4.18 asap. Normally you don't need a dump/restore but there were a couple bug-fix releases in that branch which might require one depending on what locale you're using. But that's not what's causing your problem I don't think: > Usually our program dumps core several times a day, but the reason is unknown. > All I know from the core file is the lines below. > > during PQexec(db->conn, query) it dumps core. > > Should it happen due to a connection problem between the pgsql server and our > program? What could be the resolution to avoid the coredumps? > > (gdb) up > #1 0xb7df4cff in malloc () from /lib/tls/libc.so.6 > (gdb) up > #2 0xb7eed753 in PQmakeEmptyPGresult () from /usr/lib/libpq.so.3 This core dump is from the client, not the database server. That it's coming from malloc makes me think it's likely you've done something wrong with your memory allocations previously. Double-freeing a pointer, freeing a pointer which didn't come from malloc, writing past the end or beginning of the allocated memory, etc. Any bug like this can cause random core dumps in malloc or free later. -- Gregory Stark EnterpriseDB http://www.enterprisedb.com
"Tom Lane" <tgl@sss.pgh.pa.us> writes: > Adam PAPAI <wooh@wooh.hu> writes: >> Usually our program dumps core several times a day, but the reason is >> unknown. All I know from the core file is the lines below. > > That failure is inside malloc, not PQmakeEmptyPQresult, and the odds > are extremely high that the reason is some part of your program > clobbering memory that doesn't belong to it (and thereby damaging > malloc's internal data structures). Try running your program under > Electric Fence or some other debugging malloc package. Incidentally glic comes with such a debugging malloc which you can get by defining the environment variable MALLOC_CHECK_ before starting your program. In bash you can do this by running your program with something like: MALLOC_CHECK_=3 ./myprogram -- Gregory Stark EnterpriseDB http://www.enterprisedb.com