Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2c7395a

Browse files
committed
Fix a couple of memory leaks in src/bin/pg_basebackup/
These have been introduced by7fbe0c8, and could happen forpg_basebackup and pg_receivewal.Per report from Coverity for the ones in walmethods.c, I have spottedthe ones in receivelog.c after more review.Backpatch-through: 10
1 parent2b8f3f5 commit2c7395a

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

‎src/bin/pg_basebackup/receivelog.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
118118
{
119119
pg_log_error("could not get size of write-ahead log file \"%s\": %s",
120120
fn,stream->walmethod->getlasterror());
121+
pg_free(fn);
121122
return false;
122123
}
123124
if (size==WalSegSz)
@@ -128,6 +129,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
128129
{
129130
pg_log_error("could not open existing write-ahead log file \"%s\": %s",
130131
fn,stream->walmethod->getlasterror());
132+
pg_free(fn);
131133
return false;
132134
}
133135

@@ -141,6 +143,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
141143
}
142144

143145
walfile=f;
146+
pg_free(fn);
144147
return true;
145148
}
146149
if (size!=0)
@@ -152,6 +155,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
152155
"write-ahead log file \"%s\" has %d bytes, should be 0 or %d",
153156
size),
154157
fn, (int)size,WalSegSz);
158+
pg_free(fn);
155159
return false;
156160
}
157161
/* File existed and was empty, so fall through and open */
@@ -165,9 +169,11 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
165169
{
166170
pg_log_error("could not open write-ahead log file \"%s\": %s",
167171
fn,stream->walmethod->getlasterror());
172+
pg_free(fn);
168173
return false;
169174
}
170175

176+
pg_free(fn);
171177
walfile=f;
172178
return true;
173179
}

‎src/bin/pg_basebackup/walmethods.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
9494
filename=dir_get_file_name(pathname,temp_suffix);
9595
snprintf(tmppath,sizeof(tmppath),"%s/%s",
9696
dir_data->basedir,filename);
97+
pg_free(filename);
9798

9899
/*
99100
* Open a file for non-compressed as well as compressed files. Tracking
@@ -254,11 +255,13 @@ dir_close(Walfile f, WalCloseMethod method)
254255
filename=dir_get_file_name(df->pathname,df->temp_suffix);
255256
snprintf(tmppath,sizeof(tmppath),"%s/%s",
256257
dir_data->basedir,filename);
258+
pg_free(filename);
257259

258260
/* permanent name, so no need for the prefix */
259261
filename2=dir_get_file_name(df->pathname,NULL);
260262
snprintf(tmppath2,sizeof(tmppath2),"%s/%s",
261263
dir_data->basedir,filename2);
264+
pg_free(filename2);
262265
r=durable_rename(tmppath,tmppath2);
263266
}
264267
elseif (method==CLOSE_UNLINK)
@@ -269,6 +272,7 @@ dir_close(Walfile f, WalCloseMethod method)
269272
filename=dir_get_file_name(df->pathname,df->temp_suffix);
270273
snprintf(tmppath,sizeof(tmppath),"%s/%s",
271274
dir_data->basedir,filename);
275+
pg_free(filename);
272276
r=unlink(tmppath);
273277
}
274278
else
@@ -625,11 +629,14 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
625629
if (tarCreateHeader(tar_data->currentfile->header,tmppath,NULL,0,S_IRUSR |S_IWUSR,0,0,time(NULL))!=TAR_OK)
626630
{
627631
pg_free(tar_data->currentfile);
632+
pg_free(tmppath);
628633
tar_data->currentfile=NULL;
629634
tar_set_error("could not create tar header");
630635
returnNULL;
631636
}
632637

638+
pg_free(tmppath);
639+
633640
#ifdefHAVE_LIBZ
634641
if (tar_data->compression)
635642
{

‎src/bin/pg_basebackup/walmethods.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ struct WalWriteMethod
5353
ssize_t(*get_file_size) (constchar*pathname);
5454

5555
/*
56-
* Return the name of the current file to work on, without the base
57-
* directory. This is useful for logging.
56+
* Return the name of the current file to work on in pg_malloc()'d string,
57+
*without the basedirectory. This is useful for logging.
5858
*/
5959
char*(*get_file_name) (constchar*pathname,constchar*temp_suffix);
6060

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp