• Noah Misch's avatar
    Make pgwin32_putenv() follow DLL loading and unloading. · 202dbdbe
    Noah Misch authored
    Until now, the first putenv() call of a given postgres.exe process would
    cache the set of loaded CRTs.  If a CRT unloaded after that call, the
    next putenv() would crash.  That risk was largely theoretical, because
    the first putenv() precedes all PostgreSQL-initiated module loading.
    However, this might explain bad interactions with antivirus and other
    software that injects threads asynchronously.  If an additional CRT
    loaded after the first putenv(), pgwin32_putenv() would not discover it.
    That CRT would have all environment changes predating its load, but it
    would not receive later PostgreSQL-initiated changes.  An additional CRT
    loading concurrently with the first putenv() might miss that change in
    addition to missing later changes.  Fix all those problems.  This
    removes the cache mechanism from pgwin32_putenv(); the cost, less than
    100 μs per backend startup, is negligible.
    
    No resulting misbehavior was known to be user-visible given the core
    distribution alone, but one can readily construct an affected extension
    module.  No back-patch given the lack of complaints and the potential
    for behavior changes in non-PostgreSQL code running in the backend.
    
    Christian Ullrich, reviewed by Michael Paquier.
    202dbdbe
win32env.c 3.01 KB