Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vyawP-000FAr-1u for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Mar 2026 19:34:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vyawN-006k9T-2r for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Mar 2026 19:34:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vyawN-006k9L-1x for pgsql-hackers@lists.postgresql.org; Fri, 06 Mar 2026 19:34:28 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vyawL-00000001EUw-1vS5 for pgsql-hackers@lists.postgresql.org; Fri, 06 Mar 2026 19:34:27 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-5a12f6871b2so3273988e87.1 for ; Fri, 06 Mar 2026 11:34:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1772825664; cv=none; d=google.com; s=arc-20240605; b=Q/xjHrGIKcJUnE8YDgHDx1Q33/9TbAM2W1Txh5Ml0I6gfyeINyWClwEzBSYcyhA1BK r56nJUxSqzVgXewfXn3BXA7iRbAXIP14Su0puZcaGgsGUd81EgF1w2UZ/UHLRmJem0io YvMoqDmvTBPPr++MIjIc/T9wnZudBZZkQHxtxdAovSMIGAtph90JhfBtapI+6OAItJ0B 7cXhtENFbkJvDAHeJRiTaxVU87I4lS2WReWkJNLAotPlbTeBgAh6Nu4i4yUp3RSPeW85 SLfwoDV0S0FgM1m6MlcwPerOIrW9hV0/kMzofg93ykur+Wfl44g7IphgAktCrD8yuj+D Y1kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=2RpLOtcQ6ZcER83325aX9EdSISwOJNlJwtLo8n20VGY=; fh=API7pHFvHz//VzzmsjMiZjVU2agzigd09gVcY4RidXg=; b=QhND0HoD46pmDUhTX6E9PFwL+sta3RU3L0Vj9xaNopwiPXf4hLoW6v+x+cp5+VdGkx X7BhI7yzSEg/wD8wLIdk6URqeCEAv4VafHwO0JItJj+0jSn9kUsPaKTvnLGrQUmjjSOE Osczv0P/4vlijxFLeMyXsmoGojkBwt8kjGEk6/04IKgTnu4aqnNxTvrj0LkgJigVXQqr GH0F4PpjHX7DH8XGqR1xQLrMV8LMztuzM971Xrp58putHesy0EHgHSC2Nn5tQBXQfkLV A9cnYXSASuTfTTczm5R8sobSGCR4+xYs/MZKhRNRPrCMEUJ4U7C+Nbnj3dIuKKzIMMbV KCMg==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772825664; x=1773430464; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=2RpLOtcQ6ZcER83325aX9EdSISwOJNlJwtLo8n20VGY=; b=i6GqcX1F1p5XA/zdyAOz23mwx4OiYvuLe3FuMn5u1d57TYIH28XBdvW+w3usEpgM26 shaNyxbJsktJ+LrE33FpJB1RdevtyNHUNdycrjiaI70v5sdfx0/PkQR/qmm15Cox8zKU K3SKw+ib3FEXQbDMVE6vvMuDnTYqxD+glAy0xZ/xatEXoC3U4PzSAmfap3e5a50+HjIA RPDyJijjadDy1JGs/yz3S00sFvGWmoItN0dyZCnPQukEdKWCfjlHCXYxilAKk0nxMQcP k2LkUMQTCQeG3EVks6WU2VbbHMiU0yG5d1YzzSmRrdRn9gcM/oT+96e+vzhZQ/kNqWGt E4dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772825664; x=1773430464; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=2RpLOtcQ6ZcER83325aX9EdSISwOJNlJwtLo8n20VGY=; b=pZCFltZwb+mSuXemDOnJUcxPAkkX234jdchaoGkK7k8VVMuf/o/VKO/7O5YS/FlLEH 3KwLk971Tz/pjrFN/R/SuP38qP2GPJ+/DbgzociT5Sohd4Awn0EBTLi9GKOSCLfilLUU /aR+stO4/bpt/Xm5yYBN+uKzsib1KBUAmXU/zXaVJYalmV9qBcyaWhslp5fcRfDxQOrF X+fvYe/c2kzJrxjU6bNMTb3DsO8uU8HTaosqa8F7UUEUSS4hHX0CHH/l8tjRVQ0cjsDQ DMLAcC0XV1FemIoXDOyL6svM4bEB3DV/G4BvYL/xsEyn0rjWeKxtkmsM7zE2OP5G3SoQ 2u1Q== X-Gm-Message-State: AOJu0YyHKSEXVwZO2S2Kb2SmKizPiRNQXVgBlN6P5sgN0Wu8V7UpojQh 8JGE7FVevo8N72RUb4XXnN58ZshO893lJGsz/DSIVHnhb0bPRxMBO582KURMDoeCYFxE9ID57Gl HmExQfm7sJyzpR6bNeacs1R+guIXAkNo= X-Gm-Gg: ATEYQzzHB56INXvqIURf2QGt+WvDeZ4rB1H7G7yEz31r3VwQK/0CaLaDr6YEj4O+RYy TPH8nnCw/ZNAzDXqNk7ylFCMqJFdhZ0s2fl+lzfJB0+ECqC4rDg0Kq7wvYY1GR4WOKWl74KIdLG 733lvlJabtUMzXj08Wb+MLk5bSILvrvtIYrpuxwas0wLyWZcnwteOpSNlKlozrXvITPRjryUidd 3++CjOuzne5LX1Vg9Dp3lJa1/No2HACnPfc5AEUjjbLkGtsMHBI7bIhMHTfwS+GQ0yPoRjMCh9z OBm064vR X-Received: by 2002:a05:6512:1324:b0:5a1:1c16:a443 with SMTP id 2adb3069b0e04-5a13cd338e9mr1201096e87.47.1772825663895; Fri, 06 Mar 2026 11:34:23 -0800 (PST) MIME-Version: 1.0 References: <1D199FA4-C146-493B-B29A-A1BF1084DBBC@gmail.com> <5218079D-02C5-484C-922D-BCF908A55F91@gmail.com> In-Reply-To: <5218079D-02C5-484C-922D-BCF908A55F91@gmail.com> From: Masahiko Sawada Date: Fri, 6 Mar 2026 11:33:47 -0800 X-Gm-Features: AaiRm50udQ8VfJzf5_6bw2ldoAChrbNMam8rjcT_bE8n0-FPOCpRio0BFa-Y5Uk Message-ID: Subject: Re: Trivial Fix: use palloc_array/repalloc_array for BufFile file arrays To: Chao Li Cc: Postgres hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Tue, Mar 3, 2026 at 5:31=E2=80=AFPM Chao Li wro= te: > > > > > On Dec 25, 2025, at 11:34, Chao Li wrote: > > > > > > > >> On Dec 25, 2025, at 11:12, Chao Li 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=E2=80=99s allocated by palloc_object(): > >> ``` > >> file->files =3D palloc_object(File); > >> ``` > >> > >> And reallocated by repalloc(): > >> ``` > >> file->files =3D (File *) repalloc(file->files, > >> (file->numFiles + 1) * sizeof(File)); > >> ``` > >> > >> This trivial patch just changes to use palloc_array/repalloc_array, wh= ich makes the intent clearer. > >> > >> Best regards, > >> -- > >> Chao Li (Evan) > >> HighGo Software Co., Ltd. > >> https://www.highgo.com/ > >> > >> > >> > >> > >> > > > > > > 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 =3D palloc_object(File); + file->files =3D 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