From 7f2e86404018f75174f04ade1b7a9370f0ce5a2f Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <daniel@yesql.se>
Date: Mon, 29 Apr 2019 13:30:44 +0200
Subject: [PATCH] Use pg_strdup for frontend code

Consistently use pg_strdup() for string duplication in the frontend
code where possible.  The callsites in pg_test_fsync and pg_waldump
also produced allocations which were also used before inspected.
---
 src/bin/pg_dump/dumputils.c           | 12 +++++-------
 src/bin/pg_test_fsync/pg_test_fsync.c |  2 +-
 src/bin/pg_waldump/pg_waldump.c       | 10 +++++-----
 3 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c
index 65e221157b..67691eb57a 100644
--- a/src/bin/pg_dump/dumputils.c
+++ b/src/bin/pg_dump/dumputils.c
@@ -481,15 +481,13 @@ parseAclItem(const char *item, const char *type,
 	char	   *slpos;
 	char	   *pos;
 
-	buf = strdup(item);
-	if (!buf)
-		return false;
+	buf = pg_strdup(item);
 
 	/* user or group name is string up to = */
 	eqpos = copyAclUserName(grantee, buf);
 	if (*eqpos != '=')
 	{
-		free(buf);
+		pg_free(buf);
 		return false;
 	}
 
@@ -501,13 +499,13 @@ parseAclItem(const char *item, const char *type,
 		slpos = copyAclUserName(grantor, slpos);
 		if (*slpos != '\0')
 		{
-			free(buf);
+			pg_free(buf);
 			return false;
 		}
 	}
 	else
 	{
-		free(buf);
+		pg_free(buf);
 		return false;
 	}
 
@@ -617,7 +615,7 @@ do { \
 			appendPQExpBuffer(privs, "(%s)", subname);
 	}
 
-	free(buf);
+	pg_free(buf);
 
 	return true;
 }
diff --git a/src/bin/pg_test_fsync/pg_test_fsync.c b/src/bin/pg_test_fsync/pg_test_fsync.c
index f702101742..83771061a4 100644
--- a/src/bin/pg_test_fsync/pg_test_fsync.c
+++ b/src/bin/pg_test_fsync/pg_test_fsync.c
@@ -170,7 +170,7 @@ handle_args(int argc, char *argv[])
 		switch (option)
 		{
 			case 'f':
-				filename = strdup(optarg);
+				filename = pg_strdup(optarg);
 				break;
 
 			case 's':
diff --git a/src/bin/pg_waldump/pg_waldump.c b/src/bin/pg_waldump/pg_waldump.c
index e106fb2ed1..f61505ade3 100644
--- a/src/bin/pg_waldump/pg_waldump.c
+++ b/src/bin/pg_waldump/pg_waldump.c
@@ -247,7 +247,7 @@ identify_target_directory(XLogDumpPrivate *private, char *directory,
 	{
 		if (search_directory(directory, fname))
 		{
-			private->inpath = strdup(directory);
+			private->inpath = pg_strdup(directory);
 			return;
 		}
 
@@ -255,7 +255,7 @@ identify_target_directory(XLogDumpPrivate *private, char *directory,
 		snprintf(fpath, MAXPGPATH, "%s/%s", directory, XLOGDIR);
 		if (search_directory(fpath, fname))
 		{
-			private->inpath = strdup(fpath);
+			private->inpath = pg_strdup(fpath);
 			return;
 		}
 	}
@@ -266,13 +266,13 @@ identify_target_directory(XLogDumpPrivate *private, char *directory,
 		/* current directory */
 		if (search_directory(".", fname))
 		{
-			private->inpath = strdup(".");
+			private->inpath = pg_strdup(".");
 			return;
 		}
 		/* XLOGDIR */
 		if (search_directory(XLOGDIR, fname))
 		{
-			private->inpath = strdup(XLOGDIR);
+			private->inpath = pg_strdup(XLOGDIR);
 			return;
 		}
 
@@ -283,7 +283,7 @@ identify_target_directory(XLogDumpPrivate *private, char *directory,
 			snprintf(fpath, MAXPGPATH, "%s/%s", datadir, XLOGDIR);
 			if (search_directory(fpath, fname))
 			{
-				private->inpath = strdup(fpath);
+				private->inpath = pg_strdup(fpath);
 				return;
 			}
 		}
-- 
2.14.1.145.gb3622a4ee

