diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index 2724f9ad84fb14b6ba5d55c617b035e88122a6e4..1a762eb5bc7610e524d29daaf26141cd6b592055 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.140 2008/11/11 13:19:16 heikki Exp $
+ *	  $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.141 2008/11/14 11:09:50 heikki Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -253,7 +253,6 @@ mdcreate(SMgrRelation reln, ForkNumber forkNum, bool isRedo)
 			fd = PathNameOpenFile(path, O_RDWR | PG_BINARY, 0600);
 		if (fd < 0)
 		{
-			pfree(path);
 			/* be sure to report the error reported by create, not open */
 			errno = save_errno;
 			ereport(ERROR,
@@ -499,10 +498,12 @@ mdopen(SMgrRelation reln, ForkNumber forknum, ExtensionBehavior behavior)
 			fd = PathNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, 0600);
 		if (fd < 0)
 		{
-			pfree(path);
 			if (behavior == EXTENSION_RETURN_NULL &&
 				FILE_POSSIBLY_DELETED(errno))
+			{
+				pfree(path);
 				return NULL;
+			}
 			ereport(ERROR,
 					(errcode_for_file_access(),
 					 errmsg("could not open relation %s: %m", path)));