[PostGIS] #6012: Memory leak in function lwcircstring_from_lwpointarray
PostGIS
trac at osgeo.org
Thu Nov 6 14:15:48 PST 2025
#6012: Memory leak in function lwcircstring_from_lwpointarray
-----------------------+---------------------------
Reporter: ezimanyi | Owner: pramsey
Type: defect | Status: new
Priority: medium | Milestone: PostGIS 3.6.1
Component: postgis | Version: 3.5.x
Resolution: | Keywords:
-----------------------+---------------------------
Comment (by ezimanyi):
The following MEOS program
{{{
/**
* @file
* @brief A simple MEOS program that creates a circle and prints its
* WKT representation using the liblwgeom library.
*
* The program can be build as follows
* @code
* gcc -Wall -g -I/usr/local/include -o geocircle_test geocircle_test.c
-L/usr/local/lib -lmeos
* @endcode
*/
#include <stdio.h>
#include <stdlib.h>
#include <meos.h>
#include <meos_geo.h>
extern GSERIALIZED *geocircle_make(double x, double y, double radius,
int32_t srid);
/* Main program */
int main(void)
{
/* Initialize MEOS */
meos_initialize();
GSERIALIZED *circle = geocircle_make(1, 1, 1, 5676);
char *circle_out = geo_as_ewkt(circle, 6);
printf("%s\n", circle_out);
free(circle);
free(circle_out);
/* Finalize MEOS */
meos_finalize();
return 0;
}
}}}
tested with Valgrind when commenting in/out the line
FLAGS_SET_READONLY(result->points->flags, 0);
https://github.com/estebanzimanyi/MobilityDB/blob/meos_test/postgis/liblwgeom/lwcircstring.c#L74C3-L74C21
is as follows
----------------------------------------------------------------------------------
{{{
$ valgrind -s --leak-check=full --show-leak-kinds=all ./geocircle_test
==3353068== Memcheck, a memory error detector
==3353068== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et
al.
==3353068== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright
info
==3353068== Command: ./geocircle_test
==3353068==
SRID=5676;CURVEPOLYGON(CIRCULARSTRING(0 1,2 1,0 1))
==3353068==
==3353068== HEAP SUMMARY:
==3353068== in use at exit: 0 bytes in 0 blocks
==3353068== total heap usage: 8,201 allocs, 8,201 frees, 967,211 bytes
allocated
==3353068==
==3353068== All heap blocks were freed -- no leaks are possible
==3353068==
==3353068== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
}}}
----------------------------------------------------------------------------------
{{{
$ valgrind -s --leak-check=full --show-leak-kinds=all ./geocircle_test
==3365033== Memcheck, a memory error detector
==3365033== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et
al.
==3365033== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright
info
==3365033== Command: ./geocircle_test
==3365033==
SRID=5676;CURVEPOLYGON(CIRCULARSTRING(0 1,2 1,0 1))
==3365033==
==3365033== HEAP SUMMARY:
==3365033== in use at exit: 48 bytes in 1 blocks
==3365033== total heap usage: 8,201 allocs, 8,200 frees, 967,211 bytes
allocated
==3365033==
==3365033== 48 bytes in 1 blocks are definitely lost in loss record 1 of 1
==3365033== at 0x4848899: malloc (in /usr/libexec/valgrind
/vgpreload_memcheck-amd64-linux.so)
==3365033== by 0x4A25935: default_allocator (lwutil.c:91)
==3365033== by 0x4A25EFD: lwalloc (lwutil.c:229)
==3365033== by 0x49CF81B: lwcircstring_from_lwpointarray
(lwcircstring.c:175)
==3365033== by 0x498CCFB: lwcircle_make (tcbuffer_spatialfuncs.c:111)
==3365033== by 0x498CDBB: geocircle_make (tcbuffer_spatialfuncs.c:126)
==3365033== by 0x109227: main (geocircle_test.c:26)
==3365033==
==3365033== LEAK SUMMARY:
==3365033== definitely lost: 48 bytes in 1 blocks
==3365033== indirectly lost: 0 bytes in 0 blocks
==3365033== possibly lost: 0 bytes in 0 blocks
==3365033== still reachable: 0 bytes in 0 blocks
==3365033== suppressed: 0 bytes in 0 blocks
==3365033==
==3365033== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
$
}}}
----------------------------------------------------------------------------------
--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/6012#comment:5>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.
More information about the postgis-tickets
mailing list