[postgis-tickets] r17132 - Fix memory leak in error case when valid

Paul Ramsey pramsey at cleverelephant.ca
Thu Jan 10 10:03:59 PST 2019


Author: pramsey
Date: 2019-01-10 10:03:58 -0800 (Thu, 10 Jan 2019)
New Revision: 17132

Modified:
   trunk/liblwgeom/lwin_wkt_parse.c
Log:
Fix memory leak in error case when valid
object is followed by junk text
References #4273


Modified: trunk/liblwgeom/lwin_wkt_parse.c
===================================================================
--- trunk/liblwgeom/lwin_wkt_parse.c	2019-01-10 16:21:01 UTC (rev 17131)
+++ trunk/liblwgeom/lwin_wkt_parse.c	2019-01-10 18:03:58 UTC (rev 17132)
@@ -152,6 +152,14 @@
 			global_parser_result.message = parser_error_messages[PARSER_ERROR_OTHER];
 			global_parser_result.errlocation = wkt_yylloc.last_column;
 		}
+		/* Got a completed object parsed, but errored out after... */
+		/* Due to junk after the valid WKT, eg: "POINT(1 1) foobar" */
+		/* https://trac.osgeo.org/postgis/ticket/4273 */
+		if ( global_parser_result.errcode && ! parse_rv )
+		{
+			lwgeom_free(global_parser_result.geom);
+			global_parser_result.geom = NULL;
+		}
 
 		LWDEBUGF(5, "error returned by wkt_yyparse() @ %d: [%d] '%s'",
 		            global_parser_result.errlocation,
@@ -160,13 +168,13 @@
 
 		/* Copy the global values into the return pointer */
 		*parser_result = global_parser_result;
-                wkt_yylex_destroy();
+		wkt_yylex_destroy();
 		return LW_FAILURE;
 	}
 
 	/* Copy the global value into the return pointer */
 	*parser_result = global_parser_result;
-        wkt_yylex_destroy();
+	wkt_yylex_destroy();
 	return LW_SUCCESS;
 }
 



More information about the postgis-tickets mailing list