Re: minor improvement in snapbuild: use existing interface and remove fake code - Mailing list pgsql-hackers

From ocean_li_996
Subject Re: minor improvement in snapbuild: use existing interface and remove fake code
Date
Msg-id 6b20d0d0.1c81.19a94b59251.Coremail.ocean_li_996@163.com
Whole thread Raw
In response to Re: minor improvement in snapbuild: use existing interface and remove fake code  (Yuefei Shi <shiyuefei1004@gmail.com>)
List pgsql-hackers
Hi yuefei,

Thanks for your review.

At 2025-11-18 09:13:12, "Yuefei Shi" <shiyuefei1004@gmail.com> wrote:
> - /* only build a new snapshot if we don't have a prebuilt one */
> - if (builder->snapshot == NULL)
> - {
> - builder->snapshot = SnapBuildBuildSnapshot(builder);
> - /* increase refcount for the snapshot builder */
> - SnapBuildSnapIncRefcount(builder->snapshot);
> - }
> + Snapshot snapshot =  SnapBuildGetOrBuildSnapshot(builder);

>  /*
>  * Increase refcount for the transaction we're handing the snapshot
>  * out to.
>  */
> - SnapBuildSnapIncRefcount(builder->snapshot);
> + SnapBuildSnapIncRefcount(snapshot);
>  ReorderBufferSetBaseSnapshot(builder->reorder, xid, lsn,
> - builder->snapshot);
> + snapshot);
> The snapshot created above is a temporary variable and is not recorded into builder->snapshot, which may cause a leak. 

AFAICT, the snapshot is created  and recorded into builder->snapshot in SnapBuildGetOrBuildSnapshot() if needed.  And the local variable snapshot
is just a poniter which actually pointing to builder->snapshot. Did I missed something?

Regards,
Haiyang Li


pgsql-hackers by date:

Previous
From: Masahiko Sawada
Date:
Subject: Re: postgres_fdw: Use COPY to speed up batch inserts
Next
From: Chao Li
Date:
Subject: Re: postgresql.conf.sample tab width