Обсуждение: Memory problem?

Поиск
Список
Период
Сортировка

Memory problem?

От
"Patrick Welche"
Дата:
I am having trouble with PQclear causing a segmentation fault, and I don't
really know where to look. I have 3 identical tables (only 2 come into play)
all of the form

+----------------------------------+----------------------------------+-------+
|              Field               |              Type                | Length|
+----------------------------------+----------------------------------+-------+
| leaf1                            | int4 not null                    |     4 |
| leaf2                            | int4 not null                    |     4 |
+----------------------------------+----------------------------------+-------+

and the last thing that happens before trouble is:

SELECT leaf2 FROM pers_room WHERE leaf1=1
SELECT leaf1 FROM pers_room WHERE leaf2=1
SELECT leaf2 FROM pers_comp WHERE leaf1=1
Segmentation fault (core dumped)

#0  0x40112370 in free ()
#1  0x400b5060 in _GLOBAL_OFFSET_TABLE_ () at pqsignal.c:42
#2  0x400ad3be in PQclear (res=0x76280) at fe-exec.c:325
#3  0x400a6181 in PgConnection::Exec (this=0xefbfd44c,    query=0x76280 "SELECT leaf2 FROM pers_comp WHERE leaf1=1")
atpgconnection.cc:98
 

323             /* Free the top-level tuple pointer array */
324             if (res->tuples)
325                     free(res->tuples);

and I suspect from the manpage:
    Otherwise, if the argument does not match a pointer    earlier returned by the calloc() malloc() or realloc()
function,or if    the space has been deallocated by a call to free() or realloc(), general    havoc may occur.
 

As you see from the backtrace, I am using libpq++. Anyone have a suggestion
where to look?

Cheers,

Patrick


Re: [HACKERS] Memory problem?

От
Tom Lane
Дата:
"Patrick Welche" <prlw1@newn.cam.ac.uk> writes:
> I am having trouble with PQclear causing a segmentation fault, and I don't
> really know where to look.

Not at PQclear(); almost surely, the bug lies elsewhere.  The most
likely bets are (a) that PQclear is being called twice for the same
PGresult (although this looks unlikely with the current libpq++,
since it doesn't give the calling app direct access to the PGresult),
or (b) that some random other bit of code is clobbering memory that
doesn't belong to it.  When you make a mistake like writing a little
bit past the end of a malloc'd piece of memory, the usual symptom is
coredumps in later malloc or free operations, because what you've
clobbered is malloc's memory management data structures.

Unfortunately that means the bug might be almost anywhere else in
your app :-(.  Good luck...
        regards, tom lane


Re: [HACKERS] Memory problem?

От
Vince Vielhaber
Дата:
On Tue, 15 Jun 1999, Patrick Welche wrote:

> I am having trouble with PQclear causing a segmentation fault, and I don't
> really know where to look. I have 3 identical tables (only 2 come into play)
> all of the form
> 

[snip]


> As you see from the backtrace, I am using libpq++. Anyone have a suggestion
> where to look?
> 
> Cheers,
> 
> Patrick
> 
> 

How recent is the libpq++ that you're using?

Vince.
-- 
==========================================================================
Vince Vielhaber -- KA8CSH   email: vev@michvhf.com   flame-mail: /dev/null      # include <std/disclaimers.h>
       TEAM-OS2       Online Campground Directory    http://www.camping-usa.com      Online Giftshop Superstore
http://www.cloudninegifts.com
==========================================================================





Re: [HACKERS] Memory problem?

От
"Patrick Welche"
Дата:
Vince Vielhaber wrote:
> 
> How recent is the libpq++ that you're using?

cvs from yesterday.

Cheers,

Patrick
(Still hunting for the needle...)


Re: [HACKERS] Memory problem?

От
"Patrick Welche"
Дата:
Tom Lane wrote:
> 
> "Patrick Welche" <prlw1@newn.cam.ac.uk> writes:
> > I am having trouble with PQclear causing a segmentation fault, and I don't
> > really know where to look.
> 
> Not at PQclear(); almost surely, the bug lies elsewhere.
...
> Unfortunately that means the bug might be almost anywhere else in
> your app :-(.  Good luck...

Sure enough - pass the PgDatabase as a reference was the solution!

Cheers,

Patrick


Re: [HACKERS] Memory problem?

От
Tom Lane
Дата:
"Patrick Welche" <prlw1@newn.cam.ac.uk> writes:
>>>> I am having trouble with PQclear causing a segmentation fault, and I don't
>>>> really know where to look.

> Sure enough - pass the PgDatabase as a reference was the solution!

Hmm.  If copying a PgDatabase object doesn't work, then the copy
constructor and assignment operators for it ought to be disabled
(by declaring them private).  Vince?
        regards, tom lane


Re: [HACKERS] Memory problem?

От
Vince Vielhaber
Дата:
On Fri, 18 Jun 1999, Tom Lane wrote:

> "Patrick Welche" <prlw1@newn.cam.ac.uk> writes:
> >>>> I am having trouble with PQclear causing a segmentation fault, and I don't
> >>>> really know where to look.
> 
> > Sure enough - pass the PgDatabase as a reference was the solution!
> 
> Hmm.  If copying a PgDatabase object doesn't work, then the copy
> constructor and assignment operators for it ought to be disabled
> (by declaring them private).  Vince?

Yep.  It's at the top of the list for the next updates.  I had noticed
a few things I wasn't all that thrilled with - some of 'em slipped by
and I didn't see 'em until I sent in the patches.  The docs are way
out of date too.  There's a couple odds and ends I need to tie up on
the web pages first, tho.

Vince.
-- 
==========================================================================
Vince Vielhaber -- KA8CSH   email: vev@michvhf.com   flame-mail: /dev/null      # include <std/disclaimers.h>
       TEAM-OS2       Online Campground Directory    http://www.camping-usa.com      Online Giftshop Superstore
http://www.cloudninegifts.com
==========================================================================