[PATCH] Fix possible minor memory leak (src/backend/catalog/heap.c)

Started by Ranier Vilelaalmost 4 years ago1 messages
#1Ranier Vilela
ranier.vf@gmail.com
1 attachment(s)

Hi,

Per Coverity.

Maybe this is a mistake, but,
Is it necessary or not to free the memory allocated by nodeToString?

If yes, the patch attached fixes this.

regards,

Ranier Vilela

Attachments:

fix_minor_memory_leak_heap.patchapplication/octet-stream; name=fix_minor_memory_leak_heap.patchDownload
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