• Michael Paquier's avatar
    Fix allocation logic of cryptohash context data with OpenSSL · 55fe26a4
    Michael Paquier authored
    The allocation of the cryptohash context data when building with OpenSSL
    was happening in the memory context of the caller of
    pg_cryptohash_create(), which could lead to issues with resowner cleanup
    if cascading resources are cleaned up on an error.  Like other
    facilities using resowners, move the base allocation to TopMemoryContext
    to ensure a correct cleanup on failure.
    
    The resulting code gets simpler with this commit as the context data is
    now hold by a unique opaque pointer, so as there is only one single
    allocation done in TopMemoryContext.
    
    After discussion, also change the cryptohash subroutines to return an
    error if the caller provides NULL for the context data to ease error
    detection on OOM.
    
    Author: Heikki Linnakangas
    Discussion: https://postgr.es/m/X9xbuEoiU3dlImfa@paquier.xyz
    55fe26a4
cryptohash.h 1.1 KB