pg_upgrade: Fix memory leak in check_for_unicode_update().
authorNathan Bossart <nathan@postgresql.org>
Sun, 6 Apr 2025 20:11:41 +0000 (15:11 -0500)
committerNathan Bossart <nathan@postgresql.org>
Sun, 6 Apr 2025 20:11:41 +0000 (15:11 -0500)
This function was initializing the "task" variable before a couple
of early returns.  To fix, postpone the initialization until just
before it's needed.

Per Coverity.

Discussion: https://postgr.es/m/Z_KMsUH2-FEbiNjC%40nathan

src/bin/pg_upgrade/check.c

index 8f946c4e3d67e5bae98404715ca118b1c0f28027..18c2d652bb6dac7056757936035a36a10a7c3401 100644 (file)
@@ -1825,7 +1825,7 @@ static void
 check_for_unicode_update(ClusterInfo *cluster)
 {
    UpgradeTaskReport report;
-   UpgradeTask *task = upgrade_task_create();
+   UpgradeTask *task;
    const char *query;
 
    /*
@@ -1920,6 +1920,7 @@ check_for_unicode_update(ClusterInfo *cluster)
        "        d.datname = current_database() AND "
        "        d.encoding = pg_char_to_encoding('UTF8');";
 
+   task = upgrade_task_create();
    upgrade_task_add_step(task, query,
                          process_unicode_update,
                          true, &report);