contrib/pg_freespacemap first check input argument, then relation_open.
contrib/pg_freespacemap first check input argument, then relation_open.
От:
jian he <jian.universality@gmail.com>
Дата:
Hi.
rel = relation_open(relid, AccessShareLock);
if (blkno < 0 || blkno > MaxBlockNumber)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid block number")));
--------------------
should it first check input arguments, then relation_open?
Does ereport automatically unlock the relation?
Re: contrib/pg_freespacemap first check input argument, then relation_open.
От:
Julien Rouhaud <rjuju123@gmail.com>
Дата:
Hi,
On Thu, Jul 06, 2023 at 10:14:46AM +0800, jian he wrote:
>
> In:
> https://git.postgresql.org/cgit/postgresql.git/tree/contrib/pg_freespacemap/pg_freespacemap.c
>
> rel = relation_open(relid, AccessShareLock);
>
> if (blkno < 0 || blkno > MaxBlockNumber)
> ereport(ERROR,
> (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
> errmsg("invalid block number")));
>
> --------------------
> should it first check input arguments, then relation_open?
It would probably be a slightly better approach but wouldn't really change much
in practice so I'm not sure it's worth changing now.
> Does ereport automatically unlock the relation?
Yes, locks, lwlocks, memory contexts and everything else is properly cleaned /
released in case of error.