Re: Trivial Fix: use palloc_array/repalloc_array for BufFile file arrays - Mailing list pgsql-hackers

From Chao Li
Subject Re: Trivial Fix: use palloc_array/repalloc_array for BufFile file arrays
Date
Msg-id 5218079D-02C5-484C-922D-BCF908A55F91@gmail.com
Whole thread Raw
In response to Re: Trivial Fix: use palloc_array/repalloc_array for BufFile file arrays  (Chao Li <li.evan.chao@gmail.com>)
List pgsql-hackers

> On Dec 25, 2025, at 11:34, Chao Li <li.evan.chao@gmail.com> wrote:
>
>
>
>> On Dec 25, 2025, at 11:12, Chao Li <li.evan.chao@gmail.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

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/





Attachment

pgsql-hackers by date:

Previous
From: Masahiko Sawada
Date:
Subject: Re: Is it OK to perform logging while holding a LWLock?
Next
From: Chao Li
Date:
Subject: Re: Use allocation macros in the logical replication code