]> granicus.if.org Git - postgis/commitdiff
transformation work made on an input copy (made by setSRID).
authorSandro Santilli <strk@keybit.net>
Tue, 24 Aug 2004 07:40:16 +0000 (07:40 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 24 Aug 2004 07:40:16 +0000 (07:40 +0000)
previous behaviour was unsafe (scribbling input object).

git-svn-id: http://svn.osgeo.org/postgis/trunk@728 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom_transform.c

index 971e3ce1a36a503c1c609a24476683a641b52586..f254b8ca3c087a260f655a9cfd7d52c184df69bc 100644 (file)
@@ -262,6 +262,10 @@ Datum transform_geom(PG_FUNCTION_ARGS)
                PG_RETURN_NULL();
        }
 
+       // This call will always copy given geometry
+       result = lwgeom_setSRID(geom, result_srid);
+       PG_FREE_IF_COPY(geom, 0);
+
        input_proj4_text  = (PG_GETARG_TEXT_P(1));
        output_proj4_text = (PG_GETARG_TEXT_P(2));
 
@@ -280,7 +284,7 @@ Datum transform_geom(PG_FUNCTION_ARGS)
        if ( (input_pj == NULL) || pj_errno)
        {
                pfree(input_proj4); pfree(output_proj4);
-               PG_FREE_IF_COPY(geom, 0);
+               pfree(result);
                elog(ERROR,"tranform: couldnt parse proj4 input string");
                PG_RETURN_NULL();
        }
@@ -290,15 +294,15 @@ Datum transform_geom(PG_FUNCTION_ARGS)
        {
                pfree(input_proj4); pfree(output_proj4);
                pj_free(input_pj);
-               PG_FREE_IF_COPY(geom, 0);
+               pfree(result);
                elog(ERROR,"tranform: couldnt parse proj4 output string");
                PG_RETURN_NULL();
        }
 
        //great, now we have a geometry, and input/output PJ* structs. 
        //Excellent.
-       lwgeom_transform_recursive(SERIALIZED_FORM(geom), input_pj, output_pj);
-       result = lwgeom_setSRID(geom, result_srid);
+       lwgeom_transform_recursive(SERIALIZED_FORM(result),
+               input_pj, output_pj);
 
        // clean up
        pj_free(input_pj);