diff options
author | Michael Paquier <michael@paquier.xyz> | 2021-07-26 11:14:21 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2021-07-26 11:14:21 +0900 |
commit | 4372f0685de164e769e895dbada18cad792192b2 (patch) | |
tree | a912df2b6fa1ae885beef37f1ceec51eeaaa525a /src/bin/pg_basebackup/walmethods.c | |
parent | 710fabfa2e4ec88a357dc36209547948545414c9 (diff) |
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/bin/pg_basebackup/walmethods.c')
-rw-r--r-- | src/bin/pg_basebackup/walmethods.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c index b4a872f0283..f662379fbed 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, progname); } 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 @@ -624,11 +628,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) { |