Index: src/backend/bootstrap/bootstrap.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/bootstrap/bootstrap.c,v
retrieving revision 1.165
diff -u -r1.165 bootstrap.c
--- src/backend/bootstrap/bootstrap.c	4 Aug 2003 02:39:57 -0000	1.165
+++ src/backend/bootstrap/bootstrap.c	16 Sep 2003 16:08:48 -0000
@@ -44,6 +44,7 @@
 #include "utils/guc.h"
 #include "utils/lsyscache.h"
 #include "utils/relcache.h"
+//#include "utils/memutils.h"
 
 
 #define ALLOC(t, c)		((t *) calloc((unsigned)(c), sizeof(t)))
@@ -295,12 +296,12 @@
 					if (p)
 						p = strchr(p + 1, ',');
 					if (p)
-						dbname = strdup(p + 1);
+						dbname = xstrdup(p + 1);
 #else
-					dbname = strdup(optarg);
+					dbname = xstrdup(optarg);
 #endif
 					break;
-				}
+				}                                 
 			case 'B':
 				SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
 				break;
Index: src/backend/main/main.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/main/main.c,v
retrieving revision 1.61
diff -u -r1.61 main.c
--- src/backend/main/main.c	4 Aug 2003 02:39:59 -0000	1.61
+++ src/backend/main/main.c	16 Sep 2003 16:08:48 -0000
@@ -119,7 +119,7 @@
 
 	new_argv = (char **) malloc((argc + 1) * sizeof(char *));
 	for (i = 0; i < argc; i++)
-		new_argv[i] = strdup(argv[i]);
+		new_argv[i] = xstrdup(argv[i]);
 	new_argv[argc] = NULL;
 
 	/*
@@ -244,7 +244,7 @@
 		exit(1);
 	}
 	/* Allocate new memory because later getpwuid() calls can overwrite it */
-	pw_name_persist = strdup(pw->pw_name);
+	pw_name_persist = xstrdup(pw->pw_name);
 #else
 	{
 		long		namesize = 256 /* UNLEN */ + 1;
Index: src/backend/tcop/postgres.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/tcop/postgres.c,v
retrieving revision 1.361
diff -u -r1.361 postgres.c
--- src/backend/tcop/postgres.c	26 Aug 2003 15:38:24 -0000	1.361
+++ src/backend/tcop/postgres.c	16 Sep 2003 16:08:58 -0000
@@ -2286,9 +2286,9 @@
 					for (i = 0, p = optarg - 1; i < 4 && p; i++)
 						p = strchr(p + 1, ',');
 					if (i == 4 && p)
-						dbname = strdup(p + 1);
+						dbname = xstrdup(p + 1);
 #else
-					dbname = strdup(optarg);
+					dbname = xstrdup(optarg);
 #endif
 					secure = false;		/* subsequent switches are NOT
 										 * secure */
Index: src/backend/utils/adt/pg_locale.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/pg_locale.c,v
retrieving revision 1.23
diff -u -r1.23 pg_locale.c
--- src/backend/utils/adt/pg_locale.c	4 Aug 2003 23:59:38 -0000	1.23
+++ src/backend/utils/adt/pg_locale.c	16 Sep 2003 16:08:59 -0000
@@ -237,16 +237,16 @@
 	 * overwrite localeconv()'s results.
 	 */
 	CurrentLocaleConv = *extlconv;
-	CurrentLocaleConv.currency_symbol = strdup(extlconv->currency_symbol);
-	CurrentLocaleConv.decimal_point = strdup(extlconv->decimal_point);
-	CurrentLocaleConv.grouping = strdup(extlconv->grouping);
-	CurrentLocaleConv.thousands_sep = strdup(extlconv->thousands_sep);
-	CurrentLocaleConv.int_curr_symbol = strdup(extlconv->int_curr_symbol);
-	CurrentLocaleConv.mon_decimal_point = strdup(extlconv->mon_decimal_point);
-	CurrentLocaleConv.mon_grouping = strdup(extlconv->mon_grouping);
-	CurrentLocaleConv.mon_thousands_sep = strdup(extlconv->mon_thousands_sep);
-	CurrentLocaleConv.negative_sign = strdup(extlconv->negative_sign);
-	CurrentLocaleConv.positive_sign = strdup(extlconv->positive_sign);
+	CurrentLocaleConv.currency_symbol = xstrdup(extlconv->currency_symbol);
+	CurrentLocaleConv.decimal_point = xstrdup(extlconv->decimal_point);
+	CurrentLocaleConv.grouping = xstrdup(extlconv->grouping);
+	CurrentLocaleConv.thousands_sep = xstrdup(extlconv->thousands_sep);
+	CurrentLocaleConv.int_curr_symbol = xstrdup(extlconv->int_curr_symbol);
+	CurrentLocaleConv.mon_decimal_point = xstrdup(extlconv->mon_decimal_point);
+	CurrentLocaleConv.mon_grouping = xstrdup(extlconv->mon_grouping);
+	CurrentLocaleConv.mon_thousands_sep = xstrdup(extlconv->mon_thousands_sep);
+	CurrentLocaleConv.negative_sign = xstrdup(extlconv->negative_sign);
+	CurrentLocaleConv.positive_sign = xstrdup(extlconv->positive_sign);
 	CurrentLocaleConv.n_sign_posn = extlconv->n_sign_posn;
 
 	/* Try to restore internal settings */
Index: src/backend/utils/init/findbe.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/init/findbe.c,v
retrieving revision 1.37
diff -u -r1.37 findbe.c
--- src/backend/utils/init/findbe.c	4 Aug 2003 02:40:06 -0000	1.37
+++ src/backend/utils/init/findbe.c	16 Sep 2003 16:08:59 -0000
@@ -192,7 +192,7 @@
 	if ((p = getenv("PATH")) && *p)
 	{
 		elog(DEBUG2, "searching PATH for executable");
-		path = strdup(p);		/* make a modifiable copy */
+		path = xstrdup(p);		/* make a modifiable copy */
 		for (startp = path, endp = strchr(path, ':');
 			 startp && *startp;
 			 startp = endp + 1, endp = strchr(startp, ':'))
Index: src/backend/utils/init/miscinit.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/init/miscinit.c,v
retrieving revision 1.113
diff -u -r1.113 miscinit.c
--- src/backend/utils/init/miscinit.c	4 Aug 2003 04:03:10 -0000	1.113
+++ src/backend/utils/init/miscinit.c	16 Sep 2003 16:08:59 -0000
@@ -93,7 +93,7 @@
 	/* use strdup since this is done before memory contexts are set up */
 	if (path)
 	{
-		DatabasePath = strdup(path);
+		DatabasePath = xstrdup(path);
 		AssertState(DatabasePath);
 	}
 }
@@ -150,11 +150,7 @@
 	}
 	else
 	{
-		new = strdup(dir);
-		if (!new)
-			ereport(FATAL,
-					(errcode(ERRCODE_OUT_OF_MEMORY),
-					 errmsg("out of memory")));
+		new = xstrdup(dir);
 	}
 
 	/*
@@ -577,7 +573,7 @@
 	/*
 	 * Arrange for automatic removal of lockfile at proc_exit.
 	 */
-	on_proc_exit(UnlinkLockFile, PointerGetDatum(strdup(filename)));
+	on_proc_exit(UnlinkLockFile, PointerGetDatum(xstrdup(filename)));
 }
 
 void
Index: src/backend/utils/misc/guc.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/misc/guc.c,v
retrieving revision 1.151
diff -u -r1.151 guc.c
--- src/backend/utils/misc/guc.c	26 Aug 2003 15:38:25 -0000	1.151
+++ src/backend/utils/misc/guc.c	16 Sep 2003 16:09:02 -0000
@@ -53,6 +53,7 @@
 #include "utils/builtins.h"
 #include "utils/datetime.h"
 #include "utils/pg_locale.h"
+#include "utils/memutils.h"
 #include "pgstat.h"
 
 
@@ -1854,11 +1855,8 @@
 						break;
 					}
 
-					str = strdup(conf->boot_val);
-					if (str == NULL)
-						ereport(FATAL,
-								(errcode(ERRCODE_OUT_OF_MEMORY),
-								 errmsg("out of memory")));
+					str = xstrdup(conf->boot_val);
+					
 					conf->reset_val = str;
 
 					if (conf->assign_hook)
@@ -3970,20 +3968,13 @@
 		strncpy(*name, string, equal_pos);
 		(*name)[equal_pos] = '\0';
 
-		*value = strdup(&string[equal_pos + 1]);
-		if (!*value)
-			ereport(FATAL,
-					(errcode(ERRCODE_OUT_OF_MEMORY),
-					 errmsg("out of memory")));
+		*value = xstrdup(&string[equal_pos + 1]);
 	}
 	else
 	{
 		/* no equal sign in string */
-		*name = strdup(string);
-		if (!*name)
-			ereport(FATAL,
-					(errcode(ERRCODE_OUT_OF_MEMORY),
-					 errmsg("out of memory")));
+		*name = xstrdup(string);
+		
 		*value = NULL;
 	}
 
Index: src/backend/utils/misc/ps_status.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/misc/ps_status.c,v
retrieving revision 1.14
diff -u -r1.14 ps_status.c
--- src/backend/utils/misc/ps_status.c	4 Aug 2003 23:59:39 -0000	1.14
+++ src/backend/utils/misc/ps_status.c	16 Sep 2003 16:09:02 -0000
@@ -25,6 +25,7 @@
 
 #include "miscadmin.h"
 #include "utils/ps_status.h"
+#include "utils/memutils.h"
 
 extern char **environ;
 
@@ -150,7 +151,7 @@
 		 */
 		new_environ = malloc(sizeof(char *) * (i + 1));
 		for (i = 0; environ[i] != NULL; i++)
-			new_environ[i] = strdup(environ[i]);
+			new_environ[i] = xstrdup(environ[i]);
 		new_environ[i] = NULL;
 		environ = new_environ;
 	}
Index: src/backend/utils/mmgr/aset.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/mmgr/aset.c,v
retrieving revision 1.52
diff -u -r1.52 aset.c
--- src/backend/utils/mmgr/aset.c	4 Aug 2003 02:40:08 -0000	1.52
+++ src/backend/utils/mmgr/aset.c	16 Sep 2003 16:09:04 -0000
@@ -1125,3 +1125,5 @@
 }
 
 #endif   /* MEMORY_CONTEXT_CHECKING */
+
+
Index: src/backend/utils/mmgr/mcxt.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/mmgr/mcxt.c,v
retrieving revision 1.43
diff -u -r1.43 mcxt.c
--- src/backend/utils/mmgr/mcxt.c	4 Aug 2003 02:40:08 -0000	1.43
+++ src/backend/utils/mmgr/mcxt.c	16 Sep 2003 16:09:05 -0000
@@ -620,7 +620,8 @@
 MemoryContextStrdup(MemoryContext context, const char *string)
 {
 	char	   *nstr;
-	Size		len = strlen(string) + 1;
+
+    Size		len = strlen(string) + 1;
 
 	nstr = (char *) MemoryContextAlloc(context, len);
 
@@ -628,3 +629,24 @@
 
 	return nstr;
 }
+
+
+char *xstrdup(const char *string)
+{
+    char * ret_value;
+
+    if ( !string ) {
+        elog(ERROR, "xstrdup called with a NULL pointer");
+    }
+
+    ret_value = strdup( string );
+
+    if ( !ret_value ) {
+        ereport(ERROR,
+                (errcode(ERRCODE_OUT_OF_MEMORY),
+                 errmsg("strdup out of memory")));
+    }
+
+    return ret_value;
+}
+
Index: src/bin/pg_dump/common.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/bin/pg_dump/common.c,v
retrieving revision 1.75
diff -u -r1.75 common.c
--- src/bin/pg_dump/common.c	4 Aug 2003 02:40:09 -0000	1.75
+++ src/bin/pg_dump/common.c	16 Sep 2003 16:09:06 -0000
@@ -22,6 +22,7 @@
 #include "postgres.h"
 #include "catalog/pg_class.h"
 
+
 #include <ctype.h>
 
 #include "libpq-fe.h"
Index: src/bin/psql/variables.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/variables.c,v
retrieving revision 1.13
diff -u -r1.13 variables.c
--- src/bin/psql/variables.c	4 Aug 2003 23:59:40 -0000	1.13
+++ src/bin/psql/variables.c	16 Sep 2003 16:09:06 -0000
@@ -167,9 +167,15 @@
 #endif
 		if (strcmp(current->name, name) == 0)
 		{
+            char * new_value = strdup(value);
+
+            if ( !new_value ) {
+                return false;
+            }
+
 			free(current->value);
-			current->value = strdup(value);
-			return current->value ? true : false;
+			current->value = new_value;
+			return true;
 		}
 	}
 
Index: src/include/utils/memutils.h
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/include/utils/memutils.h,v
retrieving revision 1.53
diff -u -r1.53 memutils.h
--- src/include/utils/memutils.h	4 Aug 2003 02:40:15 -0000	1.53
+++ src/include/utils/memutils.h	16 Sep 2003 16:09:07 -0000
@@ -116,6 +116,14 @@
 					  Size initBlockSize,
 					  Size maxBlockSize);
 
+/* 
+ *    Wrapper around strdup 
+ *    mcxt.c
+ */
+
+extern char *xstrdup(const char *string);
+
+
 /*
  * Recommended default alloc parameters, suitable for "ordinary" contexts
  * that might hold quite a lot of data.
