This code failed to account for the possibility that malloc() would
change errno, resulting in wrong output for %m, not to mention the
possibility of message truncation. Such a change is obviously
expected when malloc fails, but there's reason to fear that on some
platforms even a successful malloc call can modify errno.
Discussion: https://postgr.es/m/2576.
1527382833@sss.pgh.pa.us
buf = pg_malloc_extended(required_len, MCXT_ALLOC_NO_OOM);
+ errno = save_errno; /* malloc might change errno */
+
if (!buf)
{
/* memory trouble, just print what we can and get out of here */