Re: [HACKERS] PATCH: two slab-like memory allocators - Mailing list pgsql-hackers

From Robert Haas
Subject Re: [HACKERS] PATCH: two slab-like memory allocators
Date
Msg-id CA+TgmoY6F5ry7hiabiWFvU40bVgVruLB9YGP0D2O4Tb_zNXOUw@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] PATCH: two slab-like memory allocators  (Andres Freund <andres@anarazel.de>)
Responses Re: [HACKERS] PATCH: two slab-like memory allocators  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
On Wed, Mar 1, 2017 at 5:55 PM, Andres Freund <andres@anarazel.de> wrote:
> The issue was that on 32bit platforms the Datum returned by some
> functions (int2int4_sum in this case) isn't actually a separately
> allocated Datum, but rather just something embedded in a larger
> struct.  That, combined with the following code:
>         if (!peraggstate->resulttypeByVal && !*isnull &&
>                 !MemoryContextContains(CurrentMemoryContext,
>                                                            DatumGetPointer(*result)))
> seems somewhat problematic to me.  MemoryContextContains() can give
> false positives when used on memory that's not a distinctly allocated
> chunk, and if so, we violate memory lifetime rules.  It's quite
> unlikely, given the required bit patterns, but nonetheless it's making
> me somewhat uncomfortable.
>
> Do others think this isn't an issue and we can just live with it?

I think it's 100% broken to call MemoryContextContains() on something
that's not guaranteed to be a palloc'd chunk.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: [HACKERS] [PATCH] Use $ parameters as replacement characters for pg_stat_statements
Next
From: Andres Freund
Date:
Subject: Re: [HACKERS] PATCH: two slab-like memory allocators