Skip to content

Commit 966c37f

Browse files
committed
Fix some issues in pg_rewind.
* Remove invalid option character "N" from the third argument (valid option string) of getopt_long(). * Use pg_free() or pfree() to free the memory allocated by pg_malloc() or palloc() instead of always using free(). * Assume problem is no disk space if write() fails but doesn't set errno. * Fix several typos. Patch by me. Review by Michael Paquier.
1 parent aacb8b9 commit 966c37f

File tree

7 files changed

+20
-14
lines changed

7 files changed

+20
-14
lines changed

src/bin/pg_rewind/copy_fetch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ traverse_datadir(const char *datadir, process_file_callback_t callback)
4343
/*
4444
* recursive part of traverse_datadir
4545
*
46-
* parent_path is the current subdirectory's path relative to datadir,
46+
* parentpath is the current subdirectory's path relative to datadir,
4747
* or NULL at the top level.
4848
*/
4949
static void
@@ -262,5 +262,5 @@ execute_pagemap(datapagemap_t *pagemap, const char *path)
262262
copy_file_range(path, offset, offset + BLCKSZ, false);
263263
/* Ok, this block has now been copied from new data dir to old */
264264
}
265-
free(iter);
265+
pg_free(iter);
266266
}

src/bin/pg_rewind/datapagemap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ datapagemap_add(datapagemap_t *map, BlockNumber blkno)
6767
* Start iterating through all entries in the page map.
6868
*
6969
* After datapagemap_iterate, call datapagemap_next to return the entries,
70-
* until it returns NULL. After you're done, use free() to destroy the
70+
* until it returns false. After you're done, use pg_free() to destroy the
7171
* iterator.
7272
*/
7373
datapagemap_iterator_t *
@@ -122,5 +122,5 @@ datapagemap_print(datapagemap_t *map)
122122
while (datapagemap_next(iter, &blocknum))
123123
printf(" blk %u\n", blocknum);
124124

125-
free(iter);
125+
pg_free(iter);
126126
}

src/bin/pg_rewind/file_ops.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,16 @@ write_target_range(char *buf, off_t begin, size_t size)
105105
{
106106
int writelen;
107107

108+
errno = 0;
108109
writelen = write(dstfd, p, writeleft);
109110
if (writelen < 0)
111+
{
112+
/* if write didn't set errno, assume problem is no disk space */
113+
if (errno == 0)
114+
errno = ENOSPC;
110115
pg_fatal("could not write file \"%s\": %s\n",
111116
dstpath, strerror(errno));
117+
}
112118

113119
p += writelen;
114120
writeleft -= writelen;

src/bin/pg_rewind/filemap.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ process_source_file(const char *path, file_type_t type, size_t newsize,
114114
case FILE_TYPE_DIRECTORY:
115115
if (exists && !S_ISDIR(statbuf.st_mode))
116116
{
117-
/* it's a directory in target, but not in source. Strange.. */
117+
/* it's a directory in source, but not in target. Strange.. */
118118
pg_fatal("\"%s\" is not a directory\n", localpath);
119119
}
120120

@@ -135,7 +135,7 @@ process_source_file(const char *path, file_type_t type, size_t newsize,
135135
)
136136
{
137137
/*
138-
* It's a symbolic link in target, but not in source.
138+
* It's a symbolic link in source, but not in target.
139139
* Strange..
140140
*/
141141
pg_fatal("\"%s\" is not a symbolic link\n", localpath);
@@ -354,7 +354,7 @@ process_block_change(ForkNumber forknum, RelFileNode rnode, BlockNumber blkno)
354354
entry = *e;
355355
else
356356
entry = NULL;
357-
free(path);
357+
pfree(path);
358358

359359
if (entry)
360360
{
@@ -530,7 +530,7 @@ print_filemap(void)
530530
* Does it look like a relation data file?
531531
*
532532
* For our purposes, only files belonging to the main fork are considered
533-
* relation files. Other forks are alwayes copied in toto, because we cannot
533+
* relation files. Other forks are always copied in toto, because we cannot
534534
* reliably track changes to them, because WAL only contains block references
535535
* for the main fork.
536536
*/

src/bin/pg_rewind/libpq_fetch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ libpqConnect(const char *connstr)
6969
pg_free(str);
7070

7171
/*
72-
* Also check that full_page-writes are enabled. We can get torn pages if
72+
* Also check that full_page_writes is enabled. We can get torn pages if
7373
* a page is modified while we read it with pg_read_binary_file(), and we
7474
* rely on full page images to fix them.
7575
*/
@@ -465,5 +465,5 @@ execute_pagemap(datapagemap_t *pagemap, const char *path)
465465

466466
fetch_file_range(path, offset, offset + BLCKSZ);
467467
}
468-
free(iter);
468+
pg_free(iter);
469469
}

src/bin/pg_rewind/logging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ extern void pg_fatal(const char *fmt,...) pg_attribute_printf(1, 2) pg_attribute
3232

3333
extern void progress_report(bool force);
3434

35-
#endif
35+
#endif /* PG_REWIND_LOGGING_H */

src/bin/pg_rewind/pg_rewind.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ main(int argc, char **argv)
121121
}
122122
}
123123

124-
while ((c = getopt_long(argc, argv, "D:NnP", long_options, &option_index)) != -1)
124+
while ((c = getopt_long(argc, argv, "D:nP", long_options, &option_index)) != -1)
125125
{
126126
switch (c)
127127
{
@@ -370,7 +370,7 @@ sanityChecks(void)
370370
if (ControlFile_target.data_checksum_version != PG_DATA_CHECKSUM_VERSION &&
371371
!ControlFile_target.wal_log_hints)
372372
{
373-
pg_fatal("target server need to use either data checksums or \"wal_log_hints = on\"\n");
373+
pg_fatal("target server needs to use either data checksums or \"wal_log_hints = on\"\n");
374374
}
375375

376376
/*
@@ -450,7 +450,7 @@ findCommonAncestorTimeline(XLogRecPtr *recptr, TimeLineID *tli)
450450
*recptr = entry->end;
451451
*tli = entry->tli;
452452

453-
free(sourceHistory);
453+
pg_free(sourceHistory);
454454
return;
455455
}
456456
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy