diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 7e99de88b3..a5ac6f60fe 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -3795,6 +3795,7 @@ StorePartitionBound(Relation rel, Relation parent, PartitionBoundSpec *bound)
 	bool		new_null[Natts_pg_class],
 				new_repl[Natts_pg_class];
 	Oid			defaultPartOid;
+	char		*str;
 
 	/* Update pg_class tuple */
 	classRel = table_open(RelationRelationId, RowExclusiveLock);
@@ -3817,11 +3818,16 @@ StorePartitionBound(Relation rel, Relation parent, PartitionBoundSpec *bound)
 	}
 #endif
 
+	/*
+	 * To string form for storage.
+	 */
+	str = nodeToString(bound);
+
 	/* Fill in relpartbound value */
 	memset(new_val, 0, sizeof(new_val));
 	memset(new_null, false, sizeof(new_null));
 	memset(new_repl, false, sizeof(new_repl));
-	new_val[Anum_pg_class_relpartbound - 1] = CStringGetTextDatum(nodeToString(bound));
+	new_val[Anum_pg_class_relpartbound - 1] = CStringGetTextDatum(str);
 	new_null[Anum_pg_class_relpartbound - 1] = false;
 	new_repl[Anum_pg_class_relpartbound - 1] = true;
 	newtuple = heap_modify_tuple(tuple, RelationGetDescr(classRel),
@@ -3831,6 +3837,7 @@ StorePartitionBound(Relation rel, Relation parent, PartitionBoundSpec *bound)
 	CatalogTupleUpdate(classRel, &newtuple->t_self, newtuple);
 	heap_freetuple(newtuple);
 	table_close(classRel, RowExclusiveLock);
+	pfree(str);
 
 	/*
 	 * If we're storing bounds for the default partition, update