pg_waldump: Fix small memory leak when rmgr->rm_identify returns NULL.
authorAndres Freund
Wed, 30 Oct 2019 02:18:07 +0000 (19:18 -0700)
committerAndres Freund
Wed, 30 Oct 2019 02:28:34 +0000 (19:28 -0700)
This got broken in 604f7956b94, shortly after rm_identify's
introduction.

Author: Andres Freund
Discussion: https://postgr.es/m/20191029233341[email protected]
Backpatch: 9.5, where rm_identify was introduced

src/bin/pg_waldump/pg_waldump.c

index b95d467805a99c8d5e28fcdd58a8b81b8842f670..28839d76e1594f72e5cb0231c1ecff6a0402e73c 100644 (file)
@@ -533,17 +533,18 @@ XLogDumpDisplayRecord(XLogDumpConfig *config, XLogReaderState *record)
 
    XLogDumpRecordLen(record, &rec_len, &fpi_len);
 
-   id = desc->rm_identify(info);
-   if (id == NULL)
-       id = psprintf("UNKNOWN (%x)", info & ~XLR_INFO_MASK);
-
    printf("rmgr: %-11s len (rec/tot): %6u/%6u, tx: %10u, lsn: %X/%08X, prev %X/%08X, ",
           desc->rm_name,
           rec_len, XLogRecGetTotalLen(record),
           XLogRecGetXid(record),
           (uint32) (record->ReadRecPtr >> 32), (uint32) record->ReadRecPtr,
           (uint32) (xl_prev >> 32), (uint32) xl_prev);
-   printf("desc: %s ", id);
+
+   id = desc->rm_identify(info);
+   if (id == NULL)
+       printf("desc: UNKNOWN (%x) ", info & ~XLR_INFO_MASK);
+   else
+       printf("desc: %s ", id);
 
    /* the desc routine will printf the description directly to stdout */
    desc->rm_desc(NULL, record);