checking if jsonb was detoasted and releasing memory

From: Igor Stassiy <istassiy(at)gmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: checking if jsonb was detoasted and releasing memory
Date: 2015-02-12 14:26:46
Message-ID: CAKVOjexbsBBLRyzY3B3_DgohSMuJeqzXXoNVi562dNQ5vtN+-g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Let us say that the datum of type Datum contains a Jsonb* type.
Then after the call

Jsonb *jb = DatumGetJsonb(datum);

the jb might point to a palloc'ed structure, in case detoasting took place.
So the question is if this is the right way to free up the memory after
checking that the jb was detoasted?

if ((void *)jb != DatumGetPointer(datum))
pfree(jb); // free if detoasted

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2015-02-12 15:04:43 Re: checking if jsonb was detoasted and releasing memory
Previous Message Alban Hertroys 2015-02-12 13:34:46 Re: Hardware requirements for a PostGIS server