Re: Missing free_var() at end of accum_sum_final()? - Mailing list pgsql-hackers

From Joel Jacobson
Subject Re: Missing free_var() at end of accum_sum_final()?
Date
Msg-id ebf7f18e-c9b6-4c4d-b0d1-47611e58f781@app.fastmail.com
Whole thread Raw
In response to Re: Missing free_var() at end of accum_sum_final()?  (Michael Paquier <michael@paquier.xyz>)
Responses Re: Missing free_var() at end of accum_sum_final()?
List pgsql-hackers
On Thu, Feb 16, 2023, at 07:26, Michael Paquier wrote:
> 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);
> +

Thanks for looking and explaining.

I added the free_var() calls after strip_var() to match the similar existing code at the end of sqrt_var().
Not that it matters, but thought it looked nicer to keep them in the same order.

/Joel
Attachment

pgsql-hackers by date:

Previous
From: Jim Jones
Date:
Subject: Re: [PATCH] Add pretty-printed XML output option
Next
From: tender wang
Date:
Subject: wrong query result due to wang plan