[geos-devel] [GEOS] #923: Memory leak in GEOSNode
GEOS
geos-trac at osgeo.org
Wed Sep 19 02:04:02 PDT 2018
#923: Memory leak in GEOSNode
-------------------------+---------------------------
Reporter: Algunenano | Owner: geos-devel@…
Type: defect | Status: new
Priority: major | Milestone: 3.7.0
Component: Default | Version: master
Severity: Significant | Resolution:
Keywords: |
-------------------------+---------------------------
Comment (by Algunenano):
> So I am trying to checkout that number as git commit
It comes from calling `git describe --long --tags` in what was at that
moment the current master/HEAD:
{{{
$ git checkout be8b3ffb4532c5302e004a400bf0069493df7302
Previous HEAD position was 642744e5 Fix typos in getGeometryN() docs.
HEAD is now at be8b3ffb Merge branch 'fix-shadow4.8' of cvvergara/geos
into master
$ git describe --long --tags
3.7.0rc1-21-gbe8b3ffb
}}}
To be honest, I'm not sure how `gbe8b3ffb` relates to the commit.
Here is a step by step guide to reproduce the issue:
- Checkout commit before the one responsible (`^` means commit before this
one):
{{{
git checkout e7adbc55a20633064d3af49f2662b17e5ca02e47^
}}}
- Build the library (set up flags as needed):
{{{
./autogen.sh
./configure
make
}}}
- Build the test file (I placed it in the same folder as the library
(`~/dev/public/geos`):
{{{
clang -fsanitize=address geos_leak.c -lgeos_c -L./capi/.libs -L./src/.libs
-Iinclude/geos
}}}
- Run forcing the use of the local built library:
{{{
LD_LIBRARY_PATH=./capi/.libs:./src/.libs ./a.out
(no output)
}}}
- Switch to the offending commit:
{{{
git checkout e7adbc55a20633064d3af49f2662b17e5ca02e47
}}}
- Rebuild the library:
{{{
make
}}}
- Run the test binary using the newly compiled library (There is no need
to recompile it since it was linked dynamically):
{{{
LD_LIBRARY_PATH=./capi/.libs:./src/.libs ./a.out
=================================================================
==14385==ERROR: LeakSanitizer: detected memory leaks
Indirect leak of 88 byte(s) in 1 object(s) allocated from:
#0 0x55d4cca326a1 in __interceptor_malloc
(/home/raul/dev/public/geos/a.out+0xe66a1)
#1 0x7f9d7c33a5fc in operator new(unsigned long)
/build/gcc/src/gcc/libstdc++-v3/libsupc++/new_op.cc:50:40
#2 0x7f9d7c5463a2 in
geos::noding::GeometryNoder::extractSegmentStrings(geos::geom::Geometry
const&, std::vector<geos::noding::SegmentString*,
std::allocator<geos::noding::SegmentString*> >&)
/home/raul/dev/public/geos/src/noding/GeometryNoder.cpp:157:12
#3 0x7f9d7c54684b in geos::noding::GeometryNoder::getNoded()
/home/raul
}}}
You can also avoid `clang` and instead build the test file normally and
use valgrind:
{{{
gcc geos_leak.c -lgeos_c -L./capi/.libs -L./src/.libs -Iinclude/geos
}}}
Valgrind with the last good commit:
{{{
$ LD_LIBRARY_PATH=./capi/.libs:./src/.libs valgrind ./a.out
==24076== Memcheck, a memory error detector
==24076== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==24076== Using Valgrind-3.14.0.GIT and LibVEX; rerun with -h for
copyright info
==24076== Command: ./a.out
==24076==
==24076==
==24076== HEAP SUMMARY:
==24076== in use at exit: 1,152 bytes in 3 blocks
==24076== total heap usage: 65 allocs, 62 frees, 81,848 bytes allocated
==24076==
==24076== LEAK SUMMARY:
==24076== definitely lost: 0 bytes in 0 blocks
==24076== indirectly lost: 0 bytes in 0 blocks
==24076== possibly lost: 0 bytes in 0 blocks
==24076== still reachable: 1,152 bytes in 3 blocks
==24076== suppressed: 0 bytes in 0 blocks
==24076== Rerun with --leak-check=full to see details of leaked memory
==24076==
==24076== For counts of detected and suppressed errors, rerun with: -v
==24076== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
}}}
Valgrind with the last valid commit:
{{{
$ LD_LIBRARY_PATH=./capi/.libs:./src/.libs valgrind --leak-check=full
./a.out
==8512== Memcheck, a memory error detector
==8512== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==8512== Using Valgrind-3.14.0.GIT and LibVEX; rerun with -h for copyright
info
==8512== Command: ./a.out
==8512==
==8512==
==8512== HEAP SUMMARY:
==8512== in use at exit: 1,512 bytes in 11 blocks
==8512== total heap usage: 65 allocs, 54 frees, 81,848 bytes allocated
==8512==
==8512== 360 (88 direct, 272 indirect) bytes in 1 blocks are definitely
lost in loss record 10 of 11
==8512== at 0x4837DEF: operator new(unsigned long)
(vg_replace_malloc.c:334)
==8512== by 0x4B854E3: geos::noding::(anonymous
namespace)::SegmentStringExtractor::filter_ro(geos::geom::Geometry const*)
(GeometryNoder.cpp:61)
==8512== by 0x4B853A2:
geos::noding::GeometryNoder::extractSegmentStrings(geos::geom::Geometry
const&, std::vector<geos::noding::SegmentString*,
std::allocator<geos::noding::SegmentString*> >&) (GeometryNoder.cpp:157)
==8512== by 0x4B8584B: geos::noding::GeometryNoder::getNoded()
(GeometryNoder.cpp:123)
==8512== by 0x4B85A15:
geos::noding::GeometryNoder::node(geos::geom::Geometry const&)
(GeometryNoder.cpp:80)
==8512== by 0x4865497: GEOSNode_r (geos_ts_c.cpp:2450)
==8512== by 0x1092F0: main (in /home/raul/dev/public/geos/a.out)
==8512==
==8512== LEAK SUMMARY:
==8512== definitely lost: 88 bytes in 1 blocks
==8512== indirectly lost: 272 bytes in 7 blocks
==8512== possibly lost: 0 bytes in 0 blocks
==8512== still reachable: 1,152 bytes in 3 blocks
==8512== suppressed: 0 bytes in 0 blocks
==8512== Reachable blocks (those to which a pointer was found) are not
shown.
==8512== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==8512==
==8512== For counts of detected and suppressed errors, rerun with: -v
==8512== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
}}}
Hope this is useful. Let me know if you need any help.
--
Ticket URL: <https://trac.osgeo.org/geos/ticket/923#comment:8>
GEOS <http://trac.osgeo.org/geos>
GEOS (Geometry Engine - Open Source) is a C++ port of the Java Topology Suite (JTS).
More information about the geos-devel
mailing list