aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2021-07-26 11:14:11 +0900
committerMichael Paquier <michael@paquier.xyz>2021-07-26 11:14:11 +0900
commit2c7395aad7e849235faac4ead5f69700cfd3c21b (patch)
treeec1d932ba656e0a3ec602e0c9e819821f5472f4d /src
parent2b8f3f5a7c0ede24903782fcffe2553fec01bfbe (diff)
downloadpostgresql-2c7395aad7e849235faac4ead5f69700cfd3c21b.tar.gz
postgresql-2c7395aad7e849235faac4ead5f69700cfd3c21b.zip
Fix a couple of memory leaks in src/bin/pg_basebackup/
These have been introduced by 7fbe0c8, and could happen for pg_basebackup and pg_receivewal. Per report from Coverity for the ones in walmethods.c, I have spotted the ones in receivelog.c after more review. Backpatch-through: 10
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_basebackup/receivelog.c6
-rw-r--r--src/bin/pg_basebackup/walmethods.c7
-rw-r--r--src/bin/pg_basebackup/walmethods.h4
3 files changed, 15 insertions, 2 deletions
diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c
index 103c28b50b0..646bfd1e266 100644
--- a/src/bin/pg_basebackup/receivelog.c
+++ b/src/bin/pg_basebackup/receivelog.c
@@ -118,6 +118,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
{
pg_log_error("could not get size of write-ahead log file \"%s\": %s",
fn, stream->walmethod->getlasterror());
+ pg_free(fn);
return false;
}
if (size == WalSegSz)
@@ -128,6 +129,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
{
pg_log_error("could not open existing write-ahead log file \"%s\": %s",
fn, stream->walmethod->getlasterror());
+ pg_free(fn);
return false;
}
@@ -141,6 +143,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
}
walfile = f;
+ pg_free(fn);
return true;
}
if (size != 0)
@@ -152,6 +155,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
"write-ahead log file \"%s\" has %d bytes, should be 0 or %d",
size),
fn, (int) size, WalSegSz);
+ pg_free(fn);
return false;
}
/* File existed and was empty, so fall through and open */
@@ -165,9 +169,11 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
{
pg_log_error("could not open write-ahead log file \"%s\": %s",
fn, stream->walmethod->getlasterror());
+ pg_free(fn);
return false;
}
+ pg_free(fn);
walfile = f;
return true;
}
diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c
index ed272bfa552..2fc6b46f59b 100644
--- a/src/bin/pg_basebackup/walmethods.c
+++ b/src/bin/pg_basebackup/walmethods.c
@@ -94,6 +94,7 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
filename = dir_get_file_name(pathname, temp_suffix);
snprintf(tmppath, sizeof(tmppath), "%s/%s",
dir_data->basedir, filename);
+ pg_free(filename);
/*
* Open a file for non-compressed as well as compressed files. Tracking
@@ -254,11 +255,13 @@ dir_close(Walfile f, WalCloseMethod method)
filename = dir_get_file_name(df->pathname, df->temp_suffix);
snprintf(tmppath, sizeof(tmppath), "%s/%s",
dir_data->basedir, filename);
+ pg_free(filename);
/* permanent name, so no need for the prefix */
filename2 = dir_get_file_name(df->pathname, NULL);
snprintf(tmppath2, sizeof(tmppath2), "%s/%s",
dir_data->basedir, filename2);
+ pg_free(filename2);
r = durable_rename(tmppath, tmppath2);
}
else if (method == CLOSE_UNLINK)
@@ -269,6 +272,7 @@ dir_close(Walfile f, WalCloseMethod method)
filename = dir_get_file_name(df->pathname, df->temp_suffix);
snprintf(tmppath, sizeof(tmppath), "%s/%s",
dir_data->basedir, filename);
+ pg_free(filename);
r = unlink(tmppath);
}
else
@@ -625,11 +629,14 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
if (tarCreateHeader(tar_data->currentfile->header, tmppath, NULL, 0, S_IRUSR | S_IWUSR, 0, 0, time(NULL)) != TAR_OK)
{
pg_free(tar_data->currentfile);
+ pg_free(tmppath);
tar_data->currentfile = NULL;
tar_set_error("could not create tar header");
return NULL;
}
+ pg_free(tmppath);
+
#ifdef HAVE_LIBZ
if (tar_data->compression)
{
diff --git a/src/bin/pg_basebackup/walmethods.h b/src/bin/pg_basebackup/walmethods.h
index f9bd59d0cdc..2ffad2093e5 100644
--- a/src/bin/pg_basebackup/walmethods.h
+++ b/src/bin/pg_basebackup/walmethods.h
@@ -53,8 +53,8 @@ struct WalWriteMethod
ssize_t (*get_file_size) (const char *pathname);
/*
- * Return the name of the current file to work on, without the base
- * directory. This is useful for logging.
+ * Return the name of the current file to work on in pg_malloc()'d string,
+ * without the base directory. This is useful for logging.
*/
char *(*get_file_name) (const char *pathname, const char *temp_suffix);