On Thu, Aug 17, 2017 at 05:47:06PM +0000, Fabiana Zioti wrote: > int32 id = PG_GETARG_INT32(0); [..] > GSERIALIZED *geom = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(2)); [...] > PG_FREE_IF_COPY(geom, 0); You're freeing argument 0, which is an INT32, rather than the geometry argument which is 2 --strk;