[postgis-users] patch for release 1.1.3

Shoaib Burq shoaib at nomad-labs.com
Tue Jul 18 07:11:53 PDT 2006


Hi,

there are some obvious unfreed memory allocations, unused variables
and some duplicate code in the source. here's a patch against release
1.1.3 to fix them.

cheers
shoaib
-------------- next part --------------
diff -u'rNF^function' postgis-1.1.3/loader/dbfopen.c postgis-1.1.3-patched/loader/dbfopen.c
--- postgis-1.1.3/loader/dbfopen.c	2006-01-16 21:42:57.000000000 +1100
+++ postgis-1.1.3-patched/loader/dbfopen.c	2006-07-12 04:05:48.000000000 +1000
@@ -574,15 +574,21 @@
 /*      Create the file.                                                */
 /* -------------------------------------------------------------------- */
     fp = fopen( pszFullname, "wb" );
-    if( fp == NULL )
+    if( fp == NULL ) {
+	    free(pszFullname);
         return( NULL );
+    }
 
     fputc( 0, fp );
     fclose( fp );
 
     fp = fopen( pszFullname, "rb+" );
     if( fp == NULL )
+    {
+	    free(pszBasename);
+	    free(pszFullname);
         return( NULL );
+    }
 
     free( pszFullname );
 
diff -u'rNF^function' postgis-1.1.3/loader/shpopen.c postgis-1.1.3-patched/loader/shpopen.c
--- postgis-1.1.3/loader/shpopen.c	2003-12-02 07:52:00.000000000 +1100
+++ postgis-1.1.3-patched/loader/shpopen.c	2006-07-12 04:04:34.000000000 +1000
@@ -673,12 +673,21 @@
     sprintf( pszFullname, "%s.shp", pszBasename );
     fpSHP = fopen(pszFullname, "wb" );
     if( fpSHP == NULL )
-        return( NULL );
+    {
+	free(pszBasename);
+        free(pszFullname);
+	return( NULL );
+    }
 
     sprintf( pszFullname, "%s.shx", pszBasename );
     fpSHX = fopen(pszFullname, "wb" );
     if( fpSHX == NULL )
-        return( NULL );
+    {
+        free( pszFullname );
+	free( pszBasename );
+	fclose( fpSHP );
+	    return( NULL );
+    }
 
     free( pszFullname );
     free( pszBasename );
diff -u'rNF^function' postgis-1.1.3/lwgeom/liblwgeom.c postgis-1.1.3-patched/lwgeom/liblwgeom.c
--- postgis-1.1.3/lwgeom/liblwgeom.c	2006-04-18 20:28:48.000000000 +1000
+++ postgis-1.1.3-patched/lwgeom/liblwgeom.c	2006-07-12 03:29:32.000000000 +1000
@@ -79,6 +79,7 @@
 	if (!vasprintf (&msg, fmt, ap))
 	{
 		va_end (ap);
+		free(msg);
 		return;
 	}
 	printf("%s\n", msg);
@@ -101,6 +102,7 @@
 	if (!vasprintf (&msg, fmt, ap))
 	{
 		va_end (ap);
+		free(msg);
 		return;
 	}
 	fprintf(stderr, "%s\n", msg);
diff -u'rNF^function' postgis-1.1.3/lwgeom/lwgeom_api.c postgis-1.1.3-patched/lwgeom/lwgeom_api.c
--- postgis-1.1.3/lwgeom/lwgeom_api.c	2006-03-13 04:20:08.000000000 +1100
+++ postgis-1.1.3-patched/lwgeom/lwgeom_api.c	2006-07-12 03:55:44.000000000 +1000
@@ -1338,8 +1338,6 @@
 		type = MULTIPOINTTYPE;
 	if (type == LINETYPE)
 		type = MULTILINETYPE;
-	if (type == POINTTYPE)
-		type = MULTIPOINTTYPE;
 
 	if (finalType == COLLECTIONTYPE)
 		type = COLLECTIONTYPE;
diff -u'rNF^function' postgis-1.1.3/lwgeom/lwgeom_chip.c postgis-1.1.3-patched/lwgeom/lwgeom_chip.c
--- postgis-1.1.3/lwgeom/lwgeom_chip.c	2006-06-03 02:59:51.000000000 +1000
+++ postgis-1.1.3-patched/lwgeom/lwgeom_chip.c	2006-07-12 03:06:53.000000000 +1000
@@ -1070,9 +1070,6 @@
 		/* allocate a slot for a tuple with this tupdesc */
 		slot = TupleDescGetSlot(tupdesc);
 
-		/* allocate a slot for a tuple with this tupdesc */
-		slot = TupleDescGetSlot(tupdesc);
-
 		/* assign slot to function context */
 		funcctx->slot = slot;
 
diff -u'rNF^function' postgis-1.1.3/lwgeom/lwgeom_estimate.c postgis-1.1.3-patched/lwgeom/lwgeom_estimate.c
--- postgis-1.1.3/lwgeom/lwgeom_estimate.c	2006-05-30 18:38:58.000000000 +1000
+++ postgis-1.1.3-patched/lwgeom/lwgeom_estimate.c	2006-07-12 03:28:00.000000000 +1000
@@ -390,6 +390,7 @@
 	if (SPIcode  != SPI_OK_CONNECT)
 	{
 		elog(ERROR,"build_histogram2d: couldnt open a connection to SPI");
+		free(result);
 		PG_RETURN_NULL() ;
 	}
 
@@ -401,6 +402,7 @@
 	if (SPIplan  == NULL)
 	{
 		elog(ERROR,"build_histogram2d: couldnt create query plan via SPI");
+		free(result);
 		PG_RETURN_NULL() ;
 	}
 
@@ -412,6 +414,8 @@
 	if (SPIportal == NULL)
 	{
 		elog(ERROR,"build_histogram2d: couldn't create cursor via SPI");
+		
+		free(result);
 		PG_RETURN_NULL() ;
 	}
 
@@ -539,7 +543,9 @@
 	if (SPIcode  != SPI_OK_FINISH )
 	{
 		elog(ERROR,"build_histogram2d: couldnt disconnect from SPI");
-		PG_RETURN_NULL() ;
+		
+		free(result);
+		PG_RETURN_NULL();
 	}
 
 #if DEBUG_GEOMETRY_STATS
diff -u'rNF^function' postgis-1.1.3/lwgeom/lwgeom_functions_basic.c postgis-1.1.3-patched/lwgeom/lwgeom_functions_basic.c
--- postgis-1.1.3/lwgeom/lwgeom_functions_basic.c	2006-06-26 10:41:24.000000000 +1000
+++ postgis-1.1.3-patched/lwgeom/lwgeom_functions_basic.c	2006-07-12 04:07:08.000000000 +1000
@@ -554,10 +554,7 @@
 	{
 		poly = lwpoly_deserialize(serialized);
 		TYPE_SETZM(newpts.dims, 0, 0);
-		newpts.npoints = 0;
-		newpts.serialized_pointlist = lwalloc(1);
 		nrings = lwalloc(sizeof(POINTARRAY *)*poly->nrings);
-		loc = newpts.serialized_pointlist;
 		for (j=0; j<poly->nrings; j++)
 		{
 			POINTARRAY *ring = poly->rings[j];
@@ -756,10 +753,7 @@
 	{
 		poly = lwpoly_deserialize(serialized);
 		TYPE_SETZM(newpts.dims, 1, 0);
-		newpts.npoints = 0;
-		newpts.serialized_pointlist = lwalloc(1);
 		nrings = lwalloc(sizeof(POINTARRAY *)*poly->nrings);
-		loc = newpts.serialized_pointlist;
 		for (j=0; j<poly->nrings; j++)
 		{
 			POINTARRAY *ring = poly->rings[j];
@@ -934,10 +928,7 @@
 	{
 		poly = lwpoly_deserialize(serialized);
 		TYPE_SETZM(newpts.dims, 0, 1);
-		newpts.npoints = 0;
-		newpts.serialized_pointlist = lwalloc(1);
 		nrings = lwalloc(sizeof(POINTARRAY *)*poly->nrings);
-		loc = newpts.serialized_pointlist;
 		for (j=0; j<poly->nrings; j++)
 		{
 			POINTARRAY *ring = poly->rings[j];
@@ -1136,10 +1127,7 @@
 	{
 		poly = lwpoly_deserialize(serialized);
 		TYPE_SETZM(newpts.dims, 1, 1);
-		newpts.npoints = 0;
-		newpts.serialized_pointlist = lwalloc(1);
 		nrings = lwalloc(sizeof(POINTARRAY *)*poly->nrings);
-		loc = newpts.serialized_pointlist;
 		for (j=0; j<poly->nrings; j++)
 		{
 			POINTARRAY *ring = poly->rings[j];
diff -u'rNF^function' postgis-1.1.3/lwgeom/lwgeom_geos_c.c postgis-1.1.3-patched/lwgeom/lwgeom_geos_c.c
--- postgis-1.1.3/lwgeom/lwgeom_geos_c.c	2006-06-26 10:56:26.000000000 +1000
+++ postgis-1.1.3-patched/lwgeom/lwgeom_geos_c.c	2006-07-12 03:18:26.000000000 +1000
@@ -2540,7 +2540,11 @@
 			{
 				sq = ptarray_to_GEOSCoordSeq(lwpoly->rings[i]);
 				geoms[i-1] = GEOSGeom_createLinearRing(sq);
-	if ( ! geoms[i-1] ) return NULL;
+	if ( ! geoms[i-1] ) 
+	{
+		free(geoms);
+		return NULL;
+	}
 	/*lwerror("LWGEOM2GEOS: exception during polygon hole conversion"); */
 			}
 			g = GEOSGeom_createPolygon(shell, geoms, ngeoms);
@@ -2567,7 +2571,11 @@
 			for (i=0; i<ngeoms; ++i)
 			{
 				geoms[i] = LWGEOM2GEOS(lwc->geoms[i]);
-				if ( ! geoms[i] ) return NULL;
+				if ( ! geoms[i] ) 
+				{
+					free(geoms);
+					return NULL;
+				}
 			}
 			g = GEOSGeom_createCollection(geostype, geoms, ngeoms);
 			if ( ! g ) return NULL;
diff -u'rNF^function' postgis-1.1.3/lwgeom/lwgeom_ogc.c postgis-1.1.3-patched/lwgeom/lwgeom_ogc.c
--- postgis-1.1.3/lwgeom/lwgeom_ogc.c	2005-12-31 04:40:37.000000000 +1100
+++ postgis-1.1.3-patched/lwgeom/lwgeom_ogc.c	2006-07-12 03:49:41.000000000 +1000
@@ -188,6 +188,7 @@
 		if ( subgeom == NULL )
 		{
 	elog(ERROR, "What ? lwgeom_getsubgeometry_inspected returned NULL??");
+			return -1;
 		}
 
 		type = lwgeom_getType(subgeom[0]);
diff -u'rNF^function' postgis-1.1.3/lwgeom/lwgeom_pg.c postgis-1.1.3-patched/lwgeom/lwgeom_pg.c
--- postgis-1.1.3/lwgeom/lwgeom_pg.c	2006-06-01 17:07:21.000000000 +1000
+++ postgis-1.1.3-patched/lwgeom/lwgeom_pg.c	2006-07-12 03:21:04.000000000 +1000
@@ -91,6 +91,7 @@
 	if (!vasprintf (&msg, fmt, ap))
 	{
 		va_end (ap);
+		free(msg);
 		return;
 	}
 	elog(NOTICE, "%s", msg);


More information about the postgis-users mailing list