Re: Fix minor memory leak in connection string validation

Поиск
Список
Период
Сортировка
От Nathan Bossart
Тема Re: Fix minor memory leak in connection string validation
Дата
Msg-id 20240113023705.GA4039878@nathanxps13
обсуждение исходный текст
Ответ на Fix minor memory leak in connection string validation  (Jeff Davis <pgsql@j-davis.com>)
Ответы Re: Fix minor memory leak in connection string validation  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On Fri, Jan 12, 2024 at 03:06:26PM -0800, Jeff Davis wrote:
> It makes me wonder if we should use the resowner mechanism to track
> pointers to malloc'd memory. Then we could use a standard pattern for
> these kinds of cases, and it would also catch more remote issues, like
> if a pstrdup() fails in an error path (which can happen a few lines up
> if the parse fails).

That seems worth exploring.

>          if (!uses_password)
> +        {
> +            /* malloc'd, so we must free it explicitly */
> +            PQconninfoFree(opts);
> +
>              ereport(ERROR,
>                      (errcode(ERRCODE_S_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED),
>                       errmsg("password is required"),
>                       errdetail("Non-superusers must provide a password in the connection string.")));
> +        }
>      }
>  
>      PQconninfoFree(opts);

Another option could be to surround this with PG_TRY/PG_FINALLY, but your
patch seems sufficient, too.

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com



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

Предыдущее
От: Jeff Davis
Дата:
Сообщение: Re: [17] CREATE SUBSCRIPTION ... SERVER
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Fix minor memory leak in connection string validation