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
+ If your life is a hard drive, Christ can be your backup. +
In response to
pgsql-hackers by date
|Next:||From: Gregory Stark||Date: 2008-11-05 05:11:03|
|Subject: Re: [WIP] In-place upgrade|
|Previous:||From: Brendan Jurd||Date: 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: MWendt||Date: 2008-11-05 08:23:51|
|Subject: BUG #4510: memory leak with libpg.dll|
|Previous:||From: nathan wagner||Date: 2008-11-04 23:23:30|
|Subject: Re: plperl & sort|