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
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-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 Content-Type Size
/pgpatches/ssl text/x-diff 7.5 KB

In response to

Responses

Browse pgsql-bugs by date

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

Browse pgsql-hackers by date

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