From c67f366fa9f748257861ee233b47b80eb5ffa857 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 29 Mar 2015 20:02:14 -0400 Subject: Fix multiple bugs and infelicities in pg_rewind. Bugs all spotted by Coverity, including wrong realloc() size request and memory leaks. Cosmetic improvements by me. The usage of the global variable "filemap" here is still pretty awful, but at least I got rid of the gratuitous aliasing in several routines (which was helping to annoy Coverity, as well as being a bug risk). --- src/bin/pg_rewind/filemap.h | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'src/bin/pg_rewind/filemap.h') diff --git a/src/bin/pg_rewind/filemap.h b/src/bin/pg_rewind/filemap.h index 57f0f92fb90..8fa19390bc3 100644 --- a/src/bin/pg_rewind/filemap.h +++ b/src/bin/pg_rewind/filemap.h @@ -29,8 +29,7 @@ typedef enum FILE_ACTION_NONE, /* no action (we might still copy modified blocks * based on the parsed WAL) */ FILE_ACTION_TRUNCATE, /* truncate local file to 'newsize' bytes */ - FILE_ACTION_REMOVE, /* remove local file / directory / symlink */ - + FILE_ACTION_REMOVE /* remove local file / directory / symlink */ } file_action_t; typedef enum @@ -40,7 +39,7 @@ typedef enum FILE_TYPE_SYMLINK } file_type_t; -struct file_entry_t +typedef struct file_entry_t { char *path; file_type_t type; @@ -58,11 +57,9 @@ struct file_entry_t char *link_target; struct file_entry_t *next; -}; - -typedef struct file_entry_t file_entry_t; +} file_entry_t; -struct filemap_t +typedef struct filemap_t { /* * New entries are accumulated to a linked list, in process_remote_file @@ -70,7 +67,7 @@ struct filemap_t */ file_entry_t *first; file_entry_t *last; - int nlist; + int nlist; /* number of entries currently in list */ /* * After processing all the remote files, the entries in the linked list @@ -80,7 +77,7 @@ struct filemap_t * the array, and the linked list is empty. */ file_entry_t **array; - int narray; + int narray; /* current length of array */ /* * Summary information. total_size is the total size of the source cluster, @@ -88,14 +85,11 @@ struct filemap_t */ uint64 total_size; uint64 fetch_size; -}; - -typedef struct filemap_t filemap_t; - -extern filemap_t * filemap; +} filemap_t; -extern filemap_t *filemap_create(void); +extern filemap_t *filemap; +extern void filemap_create(void); extern void calculate_totals(void); extern void print_filemap(void); -- cgit v1.2.3