I wrote:
> What I have done so far is to rip out the buffer refcount save/restore
> support (including LastRefCount), change BufferIsValid to a simple
> validity check (so that you get an assert if you unpin something that
> was pinned), ...
er, make that "unpin something that *wasn't* pinned".
regards, tom lane