#include "pg_bikram_sambat.h" PG_FUNCTION_INFO_V1(text_to_bs_date); Datum text_to_bs_date(PG_FUNCTION_ARGS) { text *txt = PG_GETARG_TEXT_PP(0); char *str = text_to_cstring(txt); BSDateADT result = parse_bs_date_internal(str); pfree(str); /* # Why not pfree(txt) - it is an input argument - never pfree() an input argument passived via PG_GETARG - because these memory addresses are managed by the executor - only pfree() memory that we explicitly allocate (e.g., the result of text_to_cstring()) */ PG_RETURN_INT32(result); }