From 09f7340cf16881387380ae7db106ec72c5106d86 Mon Sep 17 00:00:00 2001 From: Jan Nidzwetzki Date: Wed, 30 Aug 2023 23:49:34 +0200 Subject: [PATCH] Fix an invalid SPI result use after free This PR fixes the invalid use of an SPI result after SPI_finish is called and the result is freed. --- src/hypertable.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/hypertable.c b/src/hypertable.c index e9fab9c8fd0..ef170906fb0 100644 --- a/src/hypertable.c +++ b/src/hypertable.c @@ -2974,10 +2974,12 @@ ts_hypertable_get_open_dim_max_value(const Hypertable *ht, int dimension_index, if (isnull) *isnull = max_isnull; + int64 max_value = max_isnull ? ts_time_get_min(timetype) : ts_time_value_to_internal(maxdat, timetype); + if ((res = SPI_finish()) != SPI_OK_FINISH) elog(ERROR, "SPI_finish failed: %s", SPI_result_code_string(res)); - return max_isnull ? ts_time_get_min(timetype) : ts_time_value_to_internal(maxdat, timetype); + return max_value; } bool