Thread: BUG #17632: a potential bug of memory leak

BUG #17632: a potential bug of memory leak

From
PG Bug reporting form
Date:
The following bug has been logged on the website:

Bug reference:      17632
Logged by:          a potential bug of memory leak
Email address:      1157401338@qq.com
PostgreSQL version: 14.5
Operating system:   ubuntu20.04
Description:

Hi, I found a potential memory leak bug in the project source
code of postgre, and I have shown the execution sequence of the program
that
may generate the bug on a graph,which can be access by
https://docimg8.docs.qq.com/image/AgAACEPRUipmYhhKHB5OOoBr8hpUfqC5.png?w=2192&h=1336
The red text illustrates the steps that generate the bug,,the file path can
be seen in the blue framed
section.


Although the code shown is for version 12.12 but is still exist in current
version


would you can help to check if this bug is true?thank you for your effort
and patience!


Re: BUG #17632: a potential bug of memory leak

From
Japin Li
Date:
On Tue, 11 Oct 2022 at 10:33, PG Bug reporting form <noreply@postgresql.org> wrote:
> The following bug has been logged on the website:
>
> Bug reference:      17632
> Logged by:          a potential bug of memory leak
> Email address:      1157401338@qq.com
> PostgreSQL version: 14.5
> Operating system:   ubuntu20.04
> Description:        
>
> Hi, I found a potential memory leak bug in the project source
> code of postgre, and I have shown the execution sequence of the program
> that
> may generate the bug on a graph,which can be access by
> https://docimg8.docs.qq.com/image/AgAACEPRUipmYhhKHB5OOoBr8hpUfqC5.png?w=2192&h=1336
> The red text illustrates the steps that generate the bug,,the file path can
> be seen in the blue framed
> section.
>
>
> Although the code shown is for version 12.12 but is still exist in current
> version
>
>
> would you can help to check if this bug is true?thank you for your effort
> and patience!

The alloc_var() release the memory before allocating memory:

    static int
    alloc_var(numeric *var, int ndigits)
    {
        digitbuf_free(var->buf);    /* SEE HERE */
        var->buf = digitbuf_alloc(ndigits + 1);
        if (var->buf == NULL)
            return -1;
        var->buf[0] = 0;
        var->digits = var->buf + 1;
        var->ndigits = ndigits;
        return 0;
    }

So, I don't think it leaks.

-- 
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.