[postgis-tickets] r16330 - Tweak a couple string allocation to use the "just right" pgsql call

Paul Ramsey pramsey at cleverelephant.ca
Thu Jan 18 06:21:46 PST 2018


Author: pramsey
Date: 2018-01-18 06:21:46 -0800 (Thu, 18 Jan 2018)
New Revision: 16330

Modified:
   trunk/libpgcommon/lwgeom_transform.c
   trunk/postgis/geobuf.c
Log:
Tweak a couple string allocation to use the "just right" pgsql call


Modified: trunk/libpgcommon/lwgeom_transform.c
===================================================================
--- trunk/libpgcommon/lwgeom_transform.c	2018-01-18 12:49:41 UTC (rev 16329)
+++ trunk/libpgcommon/lwgeom_transform.c	2018-01-18 14:21:46 UTC (rev 16330)
@@ -697,9 +697,7 @@
 
 	nsp_name = get_namespace_name(get_func_namespace(fcinfo->flinfo->fn_oid));
 	elog(DEBUG4, "%s located %s in namespace %s", __func__, get_func_name(fcinfo->flinfo->fn_oid), nsp_name);
-
-	spatialRefSysSchema = MemoryContextAlloc(CacheMemoryContext, strlen(nsp_name)+1);
-	strcpy(spatialRefSysSchema, nsp_name);
+	spatialRefSysSchema = MemoryContextStrdup(CacheMemoryContext, nsp_name);;
 	return;
 }
 

Modified: trunk/postgis/geobuf.c
===================================================================
--- trunk/postgis/geobuf.c	2018-01-18 12:49:41 UTC (rev 16329)
+++ trunk/postgis/geobuf.c	2018-01-18 14:21:46 UTC (rev 16330)
@@ -64,8 +64,7 @@
 		Oid typoid = getBaseType(tupdesc->attrs[i].atttypid);
 		char *tkey = tupdesc->attrs[i].attname.data;
 #endif
-		char *key = palloc(strlen(tkey) + 1);
-		strcpy(key, tkey);
+		char *key = pstrdup(tkey);
 		if (ctx->geom_name == NULL) {
 			if (!geom_found && typoid == TypenameGetTypid("geometry")) {
 				ctx->geom_index = i;



More information about the postgis-tickets mailing list