From 43cb05e0b804626b5b1858b1838f78bdcfb87883 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Fri, 17 Jun 2005 14:51:02 +0000 Subject: [PATCH] Memory leak fix in pg_error git-svn-id: http://svn.osgeo.org/postgis/branches/pgis_1_0@1765 b70326c6-7e19-0410-871a-916f4a2858ee --- CHANGES | 1 + lwgeom/lwgeom_pg.c | 20 +++++++------------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/CHANGES b/CHANGES index e615820a2..aec8f60a7 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,7 @@ PostGIS 1.0.2cvs ???? - Fault tolerant btree ops + - Memory Leak fix in pg_error PostGIS 1.0.1 2005/05/24 diff --git a/lwgeom/lwgeom_pg.c b/lwgeom/lwgeom_pg.c index 9dca71732..02824c92e 100644 --- a/lwgeom/lwgeom_pg.c +++ b/lwgeom/lwgeom_pg.c @@ -50,23 +50,17 @@ pg_free(void *ptr) void pg_error(const char *fmt, ...) { - char *msg; +#define ERRMSG_MAXLEN 256 + + char errmsg[ERRMSG_MAXLEN+1]; va_list ap; va_start (ap, fmt); + vsnprintf (errmsg, ERRMSG_MAXLEN, fmt, ap); + va_end (ap); - /* - * This is a GNU extension. - * Dunno how to handle errors here. - */ - if (!vasprintf (&msg, fmt, ap)) - { - va_end (ap); - return; - } - elog(ERROR, "%s", msg); - va_end(ap); - free(msg); + errmsg[ERRMSG_MAXLEN]='\0'; + elog(ERROR, "%s", errmsg); } void -- 2.40.0