Opened 10 years ago
Closed 10 years ago
#2947 closed defect (fixed)
Memory leak in lwgeom_make_valid
Reported by: | strk | Owned by: | strk |
---|---|---|---|
Priority: | blocker | Milestone: | PostGIS 2.1.5 |
Component: | postgis | Version: | 2.1.x |
Keywords: | history | Cc: |
Description
The lwgeom_make_valid function leaks memory, it's exposed by the test_lwgeom_make_valid test already:
==13713== 240 (16 direct, 224 indirect) bytes in 1 blocks are definitely lost in loss record 10 of 10 ==13713== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==13713== by 0x4E7E23B: GEOS2LWGEOM (lwgeom_geos.c:154) ==13713== by 0x4E80C10: lwgeom_make_valid (lwgeom_geos_clean.c:1050) ==13713== by 0x40904C: test_lwgeom_make_valid (cu_clean.c:73) ==13713== by 0x50A3C99: ??? (in /usr/lib/libcunit.so.1.0.1) ==13713== by 0x50A4474: CU_run_test (in /usr/lib/libcunit.so.1.0.1) ==13713== by 0x40542A: main (cu_tester.c:187)
PostGIS-2.0 is _NOT_ affected
Change History (5)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
or maybe that's the first commit that _added_ the test, showing the leak
comment:3 by , 10 years ago
The problem is with collection input when output is not a collection anymore, so basically in lwgeom_as_multi, which does an lwgeom_clone() of the passed geometry thus NOT cloning the pointarray. As a result neither of the two POINTARRAY references are marked as READONLY so you can't free one w/out the other being a double-free.
comment:4 by , 10 years ago
Wrong analisys, the cloned geometry does indeed get a READONLY flag set, which means it won't destroy the pointarray. But we created the source geometry and will be giving that one away…
I guess the cleanest thing to do here is to avoid the clone completely and do the "to-multi" locally
comment:5 by , 10 years ago
Keywords: | history added |
---|---|
Resolution: | → fixed |
Status: | new → closed |
My fault, looks like. In 2.1 branch: