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

Commit012719d

Browse files
committed
fix valgrind alerts
valgrind detected some uninitialized memory usage.Looks like shift_lsn one is a real bug.
1 parentf840ae4 commit012719d

File tree

5 files changed

+41
-17
lines changed

5 files changed

+41
-17
lines changed

‎src/data.c‎

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,13 +2001,14 @@ send_pages(ConnectionArgs* conn_arg, const char *to_fullpath, const char *from_f
20012001
{
20022002
FILE*in=NULL;
20032003
FILE*out=NULL;
2004-
inthdr_num=-1;
20052004
off_tcur_pos_out=0;
20062005
charcurr_page[BLCKSZ];
20072006
intn_blocks_read=0;
20082007
BlockNumberblknum=0;
20092008
datapagemap_iterator_t*iter=NULL;
20102009
intcompressed_size=0;
2010+
BackupPageHeader2*header=NULL;
2011+
parray*harray=NULL;
20112012

20122013
/* stdio buffers */
20132014
char*in_buf=NULL;
@@ -2046,6 +2047,8 @@ send_pages(ConnectionArgs* conn_arg, const char *to_fullpath, const char *from_f
20462047
setvbuf(in,in_buf,_IOFBF,STDIO_BUFSIZE);
20472048
}
20482049

2050+
harray=parray_new();
2051+
20492052
while (blknum<file->n_blocks)
20502053
{
20512054
PageStatepage_st;
@@ -2063,17 +2066,15 @@ send_pages(ConnectionArgs* conn_arg, const char *to_fullpath, const char *from_f
20632066
if (!out)
20642067
out=open_local_file_rw(to_fullpath,&out_buf,STDIO_BUFSIZE);
20652068

2066-
hdr_num++;
2067-
2068-
if (!*headers)
2069-
*headers= (BackupPageHeader2*)pgut_malloc(sizeof(BackupPageHeader2));
2070-
else
2071-
*headers= (BackupPageHeader2*)pgut_realloc(*headers, (hdr_num+1)*sizeof(BackupPageHeader2));
2069+
header=pgut_new0(BackupPageHeader2);
2070+
*header= (BackupPageHeader2){
2071+
.block=blknum,
2072+
.pos=cur_pos_out,
2073+
.lsn=page_st.lsn,
2074+
.checksum=page_st.checksum,
2075+
};
20722076

2073-
(*headers)[hdr_num].block=blknum;
2074-
(*headers)[hdr_num].pos=cur_pos_out;
2075-
(*headers)[hdr_num].lsn=page_st.lsn;
2076-
(*headers)[hdr_num].checksum=page_st.checksum;
2077+
parray_append(harray,header);
20772078

20782079
compressed_size=compress_and_backup_page(file,blknum,in,out,&(file->crc),
20792080
rc,curr_page,calg,clevel,
@@ -2098,12 +2099,22 @@ send_pages(ConnectionArgs* conn_arg, const char *to_fullpath, const char *from_f
20982099
* Add dummy header, so we can later extract the length of last header
20992100
* as difference between their offsets.
21002101
*/
2101-
if (*headers)
2102+
if (parray_num(harray)>0)
21022103
{
2103-
file->n_headers=hdr_num+1;
2104-
*headers= (BackupPageHeader2*)pgut_realloc(*headers, (hdr_num+2)*sizeof(BackupPageHeader2));
2105-
(*headers)[hdr_num+1].pos=cur_pos_out;
2104+
size_thdr_num=parray_num(harray);
2105+
size_ti;
2106+
2107+
file->n_headers= (int)hdr_num;/* is it valid? */
2108+
*headers= (BackupPageHeader2*)pgut_malloc0((hdr_num+1)*sizeof(BackupPageHeader2));
2109+
for (i=0;i<hdr_num;i++)
2110+
{
2111+
header= (BackupPageHeader2*)parray_get(harray,i);
2112+
(*headers)[i]=*header;
2113+
pg_free(header);
2114+
}
2115+
(*headers)[hdr_num]= (BackupPageHeader2){.pos=cur_pos_out};
21062116
}
2117+
parray_free(harray);
21072118

21082119
/* cleanup */
21092120
if (in&&fclose(in))

‎src/restore.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,8 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
557557
elog(INFO,"shift LSN: %X/%X",
558558
(uint32) (shift_lsn >>32), (uint32)shift_lsn);
559559

560-
params->shift_lsn=shift_lsn;
561560
}
561+
params->shift_lsn=shift_lsn;
562562

563563
/* for validation or restore with enabled validation */
564564
if (!params->is_restore|| !params->no_validate)

‎src/util.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ writeControlFile(ControlFileData *ControlFile, const char *path, fio_location lo
136136
#endif
137137

138138
/* copy controlFileSize */
139-
buffer=pg_malloc(ControlFileSize);
139+
buffer=pg_malloc0(ControlFileSize);
140140
memcpy(buffer,ControlFile,sizeof(ControlFileData));
141141

142142
/* Write pg_control */

‎src/utils/pgut.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,17 @@ pgut_malloc(size_t size)
877877
returnret;
878878
}
879879

880+
void*
881+
pgut_malloc0(size_tsize)
882+
{
883+
char*ret;
884+
885+
ret=pgut_malloc(size);
886+
memset(ret,0,size);
887+
888+
returnret;
889+
}
890+
880891
void*
881892
pgut_realloc(void*p,size_tsize)
882893
{

‎src/utils/pgut.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ extern int pgut_wait(int num, PGconn *connections[], struct timeval *timeout);
5959
* memory allocators
6060
*/
6161
externvoid*pgut_malloc(size_tsize);
62+
externvoid*pgut_malloc0(size_tsize);
6263
externvoid*pgut_realloc(void*p,size_tsize);
6364
externchar*pgut_strdup(constchar*str);
6465

6566
#definepgut_new(type)((type *) pgut_malloc(sizeof(type)))
67+
#definepgut_new0(type)((type *) pgut_malloc0(sizeof(type)))
6668
#definepgut_newarray(type,n)((type *) pgut_malloc(sizeof(type) * (n)))
6769

6870
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp