This looks pretty reasonable to me. Nice find. Did you think about
keeping the code path as is and just removing the first initStringInfo()
call? Removing the allocation per progress message seems like a good
idea to me. Maybe you could separate this change into two patches. One
to fix the memory leak and another to remove the allocation per message.
A committer could then decide for themselves if the second patch is
worth committing.
Thank you for the review. I hadn't thought of splitting it, but it's
a good idea. I see f1889729dd3 itself is in PG17+, so the bug fix is
a backport candidate independently of the PG19 caller bb8dff9995f.
Patches attached:
0001: drop the redundant initStringInfo() call (backport candidate)
0002: allocate the static buffer once per process via
pq_beginmessage_reuse / pq_endmessage_reuse, to avoid the
per-call allocation (master only)
Thanks,
Baji Shaik