| From: | David Rowley <dgrowleyml(at)gmail(dot)com> | 
|---|---|
| To: | Mats Kindahl <mats(dot)kindahl(at)gmail(dot)com> | 
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org | 
| Subject: | Re: Use stack-allocated StringInfoData | 
| Date: | 2025-11-03 10:27:38 | 
| Message-ID: | CAApHDvr2URad5FRknDECPsmt-FT3LukvXDbv6MzgW+_L842+xA@mail.gmail.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
On Mon, 3 Nov 2025 at 20:27, Mats Kindahl <mats(dot)kindahl(at)gmail(dot)com> wrote:
> We can use
>
>        StringInfoData info;
>        initStringInfo(&info);
>        ...
>        appendStringInfo(&info, ...);
>        ...
>        return info.data;
>
> It was corrected in an earlier commit, but that seems to have been removed so we still have a lot of these cases.
>
> I created a semantic patch to capture most of these cases, which is present in [1], but this is a slightly modified version that might be interesting to include regardless of other changes. The patch is applied and one case that couldn't be matched is manually fixed.
I think this is a worthwhile conversion. Are you able to create a more
complete version of this? The draft version does introduce quite a few
whitespace changes that aren't wanted. You've also introduced a memory
leak in check_publications(), fetch_relation_list(), jsonb_send() and
xml_errorHandler() (NB: destroyStringInfo() doesn't just pfree the
memory for the struct, it pfree's the data too). The patch shouldn't
be leaving any memory around that the current master is careful to
pfree.
Do you have any semi-automated method to find these? Or is it a case
of manually reviewing code with a makeStringInfo() call?
David
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Ajin Cherian | 2025-11-03 10:33:03 | Re: Improve pg_sync_replication_slots() to wait for primary to advance | 
| Previous Message | Bertrand Drouvot | 2025-11-03 09:55:02 | Re: Coccinelle for PostgreSQL development [1/N]: coccicheck.py |