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

Commitb0d2867

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 parentb154ee6 commitb0d2867

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
@@ -117,6 +117,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
117117
{
118118
pg_log_error("could not get size of write-ahead log file \"%s\": %s",
119119
fn,stream->walmethod->getlasterror());
120+
pg_free(fn);
120121
return false;
121122
}
122123
if (size==WalSegSz)
@@ -127,6 +128,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
127128
{
128129
pg_log_error("could not open existing write-ahead log file \"%s\": %s",
129130
fn,stream->walmethod->getlasterror());
131+
pg_free(fn);
130132
return false;
131133
}
132134

@@ -140,6 +142,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
140142
}
141143

142144
walfile=f;
145+
pg_free(fn);
143146
return true;
144147
}
145148
if (size!=0)
@@ -151,6 +154,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
151154
"write-ahead log file \"%s\" has %d bytes, should be 0 or %d",
152155
size),
153156
fn, (int)size,WalSegSz);
157+
pg_free(fn);
154158
return false;
155159
}
156160
/* File existed and was empty, so fall through and open */
@@ -164,9 +168,11 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
164168
{
165169
pg_log_error("could not open write-ahead log file \"%s\": %s",
166170
fn,stream->walmethod->getlasterror());
171+
pg_free(fn);
167172
return false;
168173
}
169174

175+
pg_free(fn);
170176
walfile=f;
171177
return true;
172178
}

‎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