From 7ca37e57407a6d102402ed62c76565de8dfdd910 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/hypertable.c b/src/hypertable.c index e9fab9c8fd0..f7918f3fc3c 100644 --- a/src/hypertable.c +++ b/src/hypertable.c @@ -2974,10 +2974,13 @@ 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