[postgis-tickets] r15863 - Fix memory leaks in BTREE operators

Sandro Santilli strk at kbt.io
Sat Sep 30 10:59:54 PDT 2017


Author: strk
Date: 2017-09-30 10:59:54 -0700 (Sat, 30 Sep 2017)
New Revision: 15863

Modified:
   trunk/postgis/lwgeom_btree.c
Log:
Fix memory leaks in BTREE operators

References #3864

Modified: trunk/postgis/lwgeom_btree.c
===================================================================
--- trunk/postgis/lwgeom_btree.c	2017-09-30 17:47:40 UTC (rev 15862)
+++ trunk/postgis/lwgeom_btree.c	2017-09-30 17:59:54 UTC (rev 15863)
@@ -52,6 +52,8 @@
 	GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
 	GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
 	int cmp = gserialized_cmp(g1, g2);
+	PG_FREE_IF_COPY(g1, 0);
+	PG_FREE_IF_COPY(g2, 1);
 	if (cmp < 0)
 		PG_RETURN_BOOL(TRUE);
 	else
@@ -64,6 +66,8 @@
 	GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
 	GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
 	int cmp = gserialized_cmp(g1, g2);
+	PG_FREE_IF_COPY(g1, 0);
+	PG_FREE_IF_COPY(g2, 1);
 	if (cmp == 0)
 		PG_RETURN_BOOL(TRUE);
 	else
@@ -76,6 +80,8 @@
 	GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
 	GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
 	int cmp = gserialized_cmp(g1, g2);
+	PG_FREE_IF_COPY(g1, 0);
+	PG_FREE_IF_COPY(g2, 1);
 	if (cmp == 0)
 		PG_RETURN_BOOL(TRUE);
 	else
@@ -88,6 +94,8 @@
 	GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
 	GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
 	int cmp = gserialized_cmp(g1, g2);
+	PG_FREE_IF_COPY(g1, 0);
+	PG_FREE_IF_COPY(g2, 1);
 	if (cmp >= 0)
 		PG_RETURN_BOOL(TRUE);
 	else
@@ -100,6 +108,8 @@
 	GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
 	GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
 	int cmp = gserialized_cmp(g1, g2);
+	PG_FREE_IF_COPY(g1, 0);
+	PG_FREE_IF_COPY(g2, 1);
 	if (cmp > 0)
 		PG_RETURN_BOOL(TRUE);
 	else
@@ -111,6 +121,9 @@
 {
 	GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
 	GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
-    PG_RETURN_INT32(gserialized_cmp(g1, g2));
+	int ret = gserialized_cmp(g1, g2);
+	PG_FREE_IF_COPY(g1, 0);
+	PG_FREE_IF_COPY(g2, 1);
+	PG_RETURN_INT32(ret);
 }
 



More information about the postgis-tickets mailing list