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

Re: Re: [BUGS] libpq does not manage SSL callbacks properly when other libraries are involved.

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Russell Smith <mr-russ(at)pws(dot)com(dot)au>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PoolSnoopy <tlatzelsberger(at)gmx(dot)at>, PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: Re: [BUGS] libpq does not manage SSL callbacks properly when other libraries are involved.
Date: 2008-11-05 05:02:29
Message-ID: 200811050502.mA552TJ20677@momjian.us (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-hackers
Magnus Hagander wrote:
> > Your analysis of this problem is right on target.  When the SSL
> > callbacks were implemented for threaded libpq, there was never any
> > thought on the effect of unloading libpq while the callbacks were still
> > registered.
> > 
> > The attached patch unregisters the callback on the close of the last
> > libpq connection.  Fortunately we require PQfinish() even if the
> > connection request failed, meaning there should be proper accounting of
> > the number of open connections with the method used in this patch.
> > 
> > We do leak some memory for every load/unload of libpq, but the leaks
> > extend beyond the SSL code to the rest of libpq so I didn't attempt to
> > address that in this patch (and no one has complained about it).
> > 
> > I also could have implemented a function to unload the SSL callbacks. 
> > It would have to have been called before libpq was unloaded, but I
> > considered it inconvenient and unlikely to be adopted by applications
> > using libpq in the short-term.
> 
> I don't see why destroy_ssl_system sets up it's own mutex (that's also
> called init_mutex). I think it'd make more sense to make the mutex
> created in init_ssl_system() visible to the destroy function, and make
> use of that one instead. You'll need to somehow interlock against these
> two functions running on different threads after all.
> 
> 
> Also, the code for destroying/unlinking appears to never be called.. The
> callchain ends in pqsecure_destroy(), which is never called.

Thanks for the review, Magnus.  I have adjusted the patch to use the
same mutex every time the counter is accessed, and adjusted the
pqsecure_destroy() call to properly decrement in the right place.

Also, I renamed the libpq global destroy function to be clearer
(the function is not exported).

-- 
  Bruce Momjian  <bruce(at)momjian(dot)us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

Attachment: /pgpatches/ssl
Description: text/x-diff (7.5 KB)

In response to

Responses

pgsql-hackers by date

Next:From: Gregory StarkDate: 2008-11-05 05:11:03
Subject: Re: [WIP] In-place upgrade
Previous:From: Brendan JurdDate: 2008-11-05 05:02:11
Subject: Re: Patch for SQL-Standard Interval output and decoupling DateStyle from IntervalStyle

pgsql-bugs by date

Next:From: MWendtDate: 2008-11-05 08:23:51
Subject: BUG #4510: memory leak with libpg.dll
Previous:From: nathan wagnerDate: 2008-11-04 23:23:30
Subject: Re: plperl & sort

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