[PATHC] Fix minor memory leak in pg_basebackup - Mailing list pgsql-hackers

From Zhang, Jie
Subject [PATHC] Fix minor memory leak in pg_basebackup
Date
Msg-id 970ad9508461469b9450b64027842331@G08CNEXMBPEKD06.g08.fujitsu.local
Whole thread Raw
Responses Re: [PATHC] Fix minor memory leak in pg_basebackup  (Michael Paquier <michael@paquier.xyz>)
List pgsql-hackers
Hi all

In some cases , PGresult is not cleared.

File: src\bin\pg_basebackup\streamutil.c

bool
RetrieveWalSegSize(PGconn *conn)
{
    PGresult   *res;
......
    res = PQexec(conn, "SHOW wal_segment_size");
    if (PQresultStatus(res) != PGRES_TUPLES_OK)
    {
        pg_log_error("could not send replication command \"%s\": %s",
                     "SHOW wal_segment_size", PQerrorMessage(conn));

        PQclear(res); // *** res  is cleared  ***
        return false;
    }
......
    /* fetch xlog value and unit from the result */
    if (sscanf(PQgetvalue(res, 0, 0), "%d%s", &xlog_val, xlog_unit) != 2)
    {
        pg_log_error("WAL segment size could not be parsed");
        return false;    // *** res  is not cleared  ***
    }
......
    if (!IsValidWalSegSize(WalSegSz))
    {
        pg_log_error(ngettext("WAL segment size must be a power of two between 1 MB and 1 GB, but the remote server
reporteda value of %d byte",
 
                              "WAL segment size must be a power of two between 1 MB and 1 GB, but the remote server
reporteda value of %d bytes",
 
                              WalSegSz),
                     WalSegSz);
        return false;   ;    // *** res  is not cleared  ***
    }
......


Here is a patch.

Best Regards!






Attachment

pgsql-hackers by date:

Previous
From: Rajkumar Raghuwanshi
Date:
Subject: Re: WIP/PoC for parallel backup
Next
From: Magnus Hagander
Date:
Subject: Re: Allow pg_read_all_stats to read pg_stat_progress_*