Re: contrib/pg_freespacemap first check input argument, then relation_open. - Mailing list pgsql-hackers

From Julien Rouhaud
Subject Re: contrib/pg_freespacemap first check input argument, then relation_open.
Date
Msg-id 20230706030933.mr4jt45d6m3yet3d@jrouhaud
Whole thread Raw
In response to contrib/pg_freespacemap first check input argument, then relation_open.  (jian he <jian.universality@gmail.com>)
List pgsql-hackers
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.



pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: test_extensions: fix inconsistency between meson.build and Makefile
Next
From: Nathan Bossart
Date:
Subject: Re: Should we remove db_user_namespace?