Skip site navigation (1) Skip section navigation (2)

BUG #2246: Bad malloc interactions: ecpg, openssl

From: "Andy Klosterman" <andrew5(at)ece(dot)cmu(dot)edu>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #2246: Bad malloc interactions: ecpg, openssl
Date: 2006-02-07 20:15:45
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-bugspgsql-patches
The following bug has been logged online:

Bug reference:      2246
Logged by:          Andy Klosterman
Email address:      andrew5(at)ece(dot)cmu(dot)edu
PostgreSQL version: 8.1.0
Operating system:   Debian testing: Linux nc3 2.4.27-2-386 #1 Wed Nov 30
21:38:51 JST 2005 i686 GNU/Linux
Description:        Bad malloc interactions: ecpg, openssl

Before going into a full description and figuring out some example code for
this situation, I'm fishing for interesting in tracking it down and fixing
it (or not).

On a program that I (pre-)compile with ecpg and connect to a remote Postgres
instance over an SSL connection (as set up in pg_hba.conf with appropriate
certificates installed) my application prematurely terminates with the
following error:
*** glibc detected *** corrupted double-linked list: 0x0807c830 ***

(Without an SSL connection (as set in ph_hba.conf) the program executes just
fine.  This leads me to cast suspicion on SSL libraries.)

The back trace from gdb looks like this (which doesn't appear to be too
informative, but looks like an exception stack):
    #0  0x401bc851 in kill () from /lib/
    #1  0x4014a309 in pthread_kill () from /lib/
    #2  0x4014a6c0 in raise () from /lib/
    #3  0x401bc606 in raise () from /lib/
    #4  0x401bd971 in abort () from /lib/
    #5  0x401ef930 in __fsetlocking () from /lib/
    #6  0x401f52b9 in malloc_usable_size () from /lib/
    #7  0x401f5395 in malloc_usable_size () from /lib/
    #8  0x401f5a43 in malloc_trim () from /lib/
    #9  0x401f5d51 in free () from /lib/
    #10 0x4052ce6c in zcfree () from /usr/lib/
    #11 0x4052f83f in inflateEnd () from /usr/lib/
    #12 0x4040f262 in COMP_rle () from
    #13 0x0807e680 in ?? ()
    #14 0x00000000 in ?? ()

After a bit of digging around online, I discovered the MALLOC_CHECK_
environment variable and how it changes the behavior of malloc (man 3
malloc).  The above back trace was without MALLOC_CHECK_ in the environment
(e.g., unsetenv MALLOC_CHECK_).

Running with MALLOC_CHECK_ equal to 2 or 1 allows my program to run to

With MALLOC_CHECK_ set to 0 (which is supposed to ignore corruption), I get
a segfault.  Running inside gdb gets me the following back trace:
    #0  0x403d6f73 in ASN1_template_free ()
       from /usr/lib/i686/cmov/
    #1  0x403d6e0d in ASN1_primitive_free ()
       from /usr/lib/i686/cmov/
    #2  0x403d7023 in ASN1_item_free () from
    #3  0x403d0c07 in X509_CERT_AUX_free ()
       from /usr/lib/i686/cmov/
    #4  0x403d077a in X509_CINF_free () from
    #5  0x403d6e35 in ASN1_primitive_free ()
       from /usr/lib/i686/cmov/
    #6  0x403d7023 in ASN1_item_free () from
    #7  0x403d0927 in X509_free () from
    #8  0x402d16f3 in pqsecure_destroy () from /usr/lib/
    #9  0x402c387a in PQconninfoFree () from /usr/lib/
    #10 0x402c39c3 in PQfinish () from /usr/lib/
    #11 0x4002f41b in ECPGget_connection () from /usr/lib/
    #12 0x40030223 in ECPGdisconnect () from /usr/lib/
    #13 0x0804a113 in DBDisconnect (arg_connection=0x8054faf
        at client_test.pgcc:215
    #14 0x0804a64e in DoCorrectnessChecks () at client_test.pgcc:278
    #15 0x0804aaa1 in main (argc=7, argv=0xbffffa84) at

PURE SPECULATION:  It looks like there is either trouble in the interaction
between Postgres and the SSL library or just a bit of trouble within the SSL
SPECULATION: Another possibility is that I misunderstand some aspect of
multi-threaded interactions with Postgres (I open uniquely named connections
to the DB for each thread of my test program).  Maybe I need to have a
"lock" around the code that makes DB connections and make sure that only one
happens at a time (might be better handled within Postgres/SSL if that is
the case).

PROCEEDING FURTHER: If there is any desire on the part of any developers to
pursue this further, I'm open.  As things stand right now, I have
1. Don't use an SSL connection to the DB.
2. Do a "setenv MALLOC_CHECK_ 1" (or 2) and it works.


pgsql-bugs by date

Next:From: Michael FuhrDate: 2006-02-08 06:58:39
Subject: Re: BUG #2236: extremely slow to get unescaped bytea data
Previous:From: Tom LaneDate: 2006-02-07 18:04:44
Subject: Re: vacuum segmentation fault

pgsql-patches by date

Next:From: Simon RiggsDate: 2006-02-07 21:44:27
Subject: Re: TODO-Item: B-tree fillfactor control
Previous:From: Bruce MomjianDate: 2006-02-07 16:04:15
Subject: Re: Improve the comparison of NUMERIC data

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group