| From: | Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> |
|---|---|
| To: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
| Cc: | Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Trivial Fix: use palloc_array/repalloc_array for BufFile file arrays |
| Date: | 2026-03-06 19:33:47 |
| Message-ID: | CAD21AoDwp1D6-xm3p28RvUJKHcZM+9YtjUzNk38kLitN_Nbq4Q@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
On Tue, Mar 3, 2026 at 5:31 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>
>
>
> > On Dec 25, 2025, at 11:34, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
> >
> >
> >
> >> On Dec 25, 2025, at 11:12, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
> >>
> >> Hi Hackers,
> >>
> >> I noticed this error while working on [1].
> >>
> >> In BufFile, the fields is claimed as an array:
> >> ```
> >> struct BufFile
> >> {
> >> File *files; /* palloc'd array with numFiles entries */
> >> ```
> >>
> >> However, it’s allocated by palloc_object():
> >> ```
> >> file->files = palloc_object(File);
> >> ```
> >>
> >> And reallocated by repalloc():
> >> ```
> >> file->files = (File *) repalloc(file->files,
> >> (file->numFiles + 1) * sizeof(File));
> >> ```
> >>
> >> This trivial patch just changes to use palloc_array/repalloc_array, which makes the intent clearer.
> >>
> >> Best regards,
> >> --
> >> Chao Li (Evan)
> >> HighGo Software Co., Ltd.
> >> https://www.highgo.com/
> >>
> >>
> >>
> >>
> >> <v1-0001-Use-palloc_array-repalloc_array-for-BufFile-file-.patch>
> >
> >
> > Sorry for missing the reference of [1]:
> >
> > [1] https://postgr.es/m/aUStrqoOCDRFAq1M@paquier.xyz
> >
> > Best regards,
> > --
> > Chao Li (Evan)
> > HighGo Software Co., Ltd.
> > https://www.highgo.com/
> >
>
> PFA v2:
> * Rebased
> * Updated the commit message
I've reviewed the v2 patch and here is a comment:
- file->files = palloc_object(File);
+ file->files = palloc_array(File, 1);
I'm not a fan of this change. This change looks like trying to
distinguish allocated memory by palloc_object() and palloc_array()
even though underlying memory is identical. I'm concerned about this
change creating unnecessary coding conventions.
Regards,
--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Alexander Kuzmenkov | 2026-03-06 19:35:32 | "pg_ctl stop" stops working after a backend crash |
| Previous Message | Andres Freund | 2026-03-06 19:31:06 | Re: Mis-use of type BlockNumber? |