Re: Missing free_var() at end of accum_sum_final()?

Поиск
Список
Период
Сортировка
От Michael Paquier
Тема Re: Missing free_var() at end of accum_sum_final()?
Дата
Msg-id Y+3Mkq0DoI31Ek5u@paquier.xyz
обсуждение исходный текст
Ответ на Missing free_var() at end of accum_sum_final()?  ("Joel Jacobson" <joel@compiler.org>)
Ответы Re: Missing free_var() at end of accum_sum_final()?
Re: Missing free_var() at end of accum_sum_final()?
Список pgsql-hackers
On Thu, Feb 16, 2023 at 06:59:13AM +0100, Joel Jacobson wrote:
> I noticed the NumericVar's pos_var and neg_var are not free_var()'d
> at the end of accum_sum_final().
>
> The potential memory leak seems small, since the function is called
> only once per sum() per worker (and from a few more places), but
> maybe they should be free'd anyways for correctness?

Indeed, it is true that any code path of numeric.c that relies on a
NumericVar with an allocation done in its buffer is careful enough to
free it, except for generate_series's SRF where one step of the
computation is done.  I don't see directly why you could not do the
following:
@@ -11973,6 +11973,9 @@ accum_sum_final(NumericSumAccum *accum, NumericVar *result)
    /* And add them together */
    add_var(&pos_var, &neg_var, result);

+   free_var(&pos_var);
+   free_var(&neg_var);
+
    /* Remove leading/trailing zeroes */
    strip_var(result);
--
Michael

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Hayato Kuroda (Fujitsu)"
Дата:
Сообщение: RE: Time delayed LR (WAS Re: logical replication restrictions)
Следующее
От: Amit Kapila
Дата:
Сообщение: Re: Support logical replication of global object commands