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.