[GRASS-dev] v.net.visibility memory leak? - was Re: [GRASS-user] traveling salesman problem in air

Markus Neteler neteler at osgeo.org
Wed Apr 15 18:13:17 EDT 2009


(moving to grass-dev)

[Martina - we need to investigate a bit]

On Wed, Apr 15, 2009 at 10:42 PM, Martina Schäfer
<Martina.Schafer at ebc.uu.se> wrote:
> Interesting discussion!! I've created the centroids but unfortunately, the
> visibility network module repeatedly crashed (I am using GRASS 6.4 on Mac
> OS, but tried on Windows XP as well) with the message "out of memory".

I have run valgrind to check for a memory leak (Linux 64 bit box):
Some funky "uninitialised byte(s)" problem appears... (inline also a
debug msg?):


GRASS 6.5.svn (spearfish60): > CMD="v.net.visibility input=roads
output=graph --o"
GRASS 6.5.svn (spearfish60): > valgrind --tool=memcheck
--leak-check=yes --show-reachable=yes  $CMD --o
==3496== Memcheck, a memory error detector.
==3496== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==3496== Using LibVEX rev 1854, a library for dynamic binary translation.
==3496== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==3496== Using valgrind-3.3.1, a dynamic binary instrumentation framework.
==3496== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==3496== For more details, rerun with: -v
==3496==
==3496== Syscall param write(buf) points to uninitialised byte(s)
==3496==    at 0x7035D70: write (in /lib64/libc-2.8.so)
==3496==    by 0x6FD6EE9: _IO_file_write (in /lib64/libc-2.8.so)
==3496==    by 0x6FD7DF8: _IO_do_write (in /lib64/libc-2.8.so)
==3496==    by 0x6FD89F6: _IO_switch_to_get_mode (in /lib64/libc-2.8.so)
==3496==    by 0x6FD736F: _IO_file_seekoff (in /lib64/libc-2.8.so)
==3496==    by 0x6FCCDA9: ftell (in /lib64/libc-2.8.so)
==3496==    by 0x5D41F4D: dig_ftell (file.c:40)
==3496==    by 0x5D42963: dig__write_head (head.c:56)
==3496==    by 0x4E57FE4: V1_open_new_nat (open_nat.c:127)
==3496==    by 0x4E57434: Vect_open_new (open.c:565)
==3496==    by 0x402EAF: main (main.c:85)
==3496==  Address 0x4028009 is not stack'd, malloc'd or (recently) free'd
Building topology for vector map <graph>...
Registering primitives...
330643 primitives registered
661286 vertices registered
primitives: 402.000000
Building areas...
 100%
0 areas built
0 isles built
areas: 1.000000
Attaching islands...
isles: 0.000000
Attaching centroids...
 100%
centroids: 1.000000
areas to cidx: 0.000000                  <<--- should this be G_debug()?
Number of nodes: 4491
Number of primitives: 330643
Number of points: 0
Number of lines: 330643
Number of boundaries: 0
Number of centroids: 0
Number of areas: 0
Number of isles: 0
==3496==
==3496== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 1)
==3496== malloc/free: in use at exit: 489,152,702 bytes in 2,067,875 blocks.
==3496== malloc/free: 4,047,776 allocs, 1,979,901 frees, 1,604,422,635
bytes allocated.
==3496== For counts of detected errors, rerun with: -v
==3496== searching for pointers to 2,067,875 not-freed blocks.
==3496== checked 73,330,480 bytes.
==3496==
==3496==
==3496== 192 bytes in 8 blocks are possibly lost in loss record 1 of 21
==3496==    at 0x4C2136E: malloc (vg_replace_malloc.c:207)
==3496==    by 0x529603E: G__malloc (alloc.c:41)
==3496==    by 0x4E3E213: Vect__new_cats_struct (cats.c:62)
==3496==    by 0x4E3E1C4: Vect_new_cats_struct (cats.c:44)
==3496==    by 0x404EB4: report (visibility.c:212)
==3496==    by 0x404E5B: handle (visibility.c:198)
==3496==    by 0x4050E7: construct_visibility (visibility.c:278)
==3496==    by 0x4030EF: main (main.c:125)
==3496==
==3496==
==3496== 256 bytes in 8 blocks are still reachable in loss record 2 of 21
==3496==    at 0x4C2136E: malloc (vg_replace_malloc.c:207)
==3496==    by 0x4E4F2F2: Vect__new_line_struct (line.c:69)
==3496==    by 0x4E4F2A8: Vect_new_line_struct (line.c:59)
==3496==    by 0x404EAB: report (visibility.c:211)
==3496==    by 0x404C70: handle (visibility.c:176)
==3496==    by 0x4050E7: construct_visibility (visibility.c:278)
==3496==    by 0x4030EF: main (main.c:125)
==3496==
==3496==
==3496== 480 bytes in 15 blocks are possibly lost in loss record 3 of 21
==3496==    at 0x4C2136E: malloc (vg_replace_malloc.c:207)
==3496==    by 0x4E4F2F2: Vect__new_line_struct (line.c:69)
==3496==    by 0x4E4F2A8: Vect_new_line_struct (line.c:59)
==3496==    by 0x404EAB: report (visibility.c:211)
==3496==    by 0x404C70: handle (visibility.c:176)
==3496==    by 0x4050E7: construct_visibility (visibility.c:278)
==3496==    by 0x4030EF: main (main.c:125)
==3496==
==3496==
==3496== 480 bytes in 1 blocks are still reachable in loss record 4 of 21
==3496==    at 0x4C2136E: malloc (vg_replace_malloc.c:207)
==3496==    by 0x5296135: G__realloc (alloc.c:109)
==3496==    by 0x4E46602: Vect_add_dblink (field.c:226)
==3496==    by 0x4E47333: Vect_read_dblinks (field.c:645)
==3496==    by 0x4E56D61: Vect__open_old (open.c:344)
==3496==    by 0x4E57029: Vect_open_old (open.c:415)
==3496==    by 0x402E5F: main (main.c:81)
==3496==
==3496==
==3496== 2,048 bytes in 4 blocks are definitely lost in loss record 5 of 21
==3496==    at 0x4C2136E: malloc (vg_replace_malloc.c:207)
==3496==    by 0x5F545D6: RTreeNewNode (node.c:49)
==3496==    by 0x5F5364C: RTreeNewIndex (index.c:29)
==3496==    by 0x5D4B522: dig_spidx_init (spindex.c:36)
==3496==    by 0x5D43C94: dig_init_plus (plus.c:94)
==3496==    by 0x4E564B2: Vect__open_old (open.c:146)
==3496==    by 0x4E57029: Vect_open_old (open.c:415)
==3496==    by 0x402E5F: main (main.c:81)
==3496==
==3496==
==3496== 4,800 bytes in 6 blocks are indirectly lost in loss record 6 of 21
==3496==    at 0x4C1F144: calloc (vg_replace_malloc.c:397)
==3496==    by 0x5D3FAF5: dig__frealloc (allocation.c:144)
==3496==    by 0x5D3F991: dig__alloc_space (allocation.c:83)
==3496==    by 0x5D4D3C9: dig_alloc_points (struct_alloc.c:239)
==3496==    by 0x4E5B200: Vect__Read_line_nat (read_nat.c:309)
==3496==    by 0x4E5AD24: V2_read_line_nat (read_nat.c:138)
==3496==    by 0x4E5A9E3: Vect_read_line (read.c:106)
==3496==    by 0x403403: count (main.c:200)
==3496==    by 0x402FE6: main (main.c:108)
==3496==
==3496==
==3496== 33,700 bytes in 85 blocks are still reachable in loss record 7 of 21
==3496==    at 0x4C1F144: calloc (vg_replace_malloc.c:397)
==3496==    by 0x5D3F976: dig__alloc_space (allocation.c:81)
==3496==    by 0x5D4983D: buf_alloc (portable.c:55)
==3496==    by 0x5D49B0E: dig__fread_port_L (portable.c:150)
==3496==    by 0x5D4872D: dig_Rd_Plus_head (plus_struct.c:614)
==3496==    by 0x4E579D6: Vect_open_topo (open.c:722)
==3496==    by 0x4E5693A: Vect__open_old (open.c:229)
==3496==    by 0x4E57029: Vect_open_old (open.c:415)
==3496==    by 0x402E5F: main (main.c:81)
==3496==
==3496==
==3496== 38,440 bytes in 1,356 blocks are still reachable in loss
record 8 of 21
==3496==    at 0x4C2136E: malloc (vg_replace_malloc.c:207)
==3496==    by 0x4C214F7: realloc (vg_replace_malloc.c:429)
==3496==    by 0x5D4D0A8: dig_alloc_nodes (struct_alloc.c:99)
==3496==    by 0x5D44166: dig_load_plus (plus.c:290)
==3496==    by 0x4E57AC5: Vect_open_topo (open.c:751)
==3496==    by 0x4E5693A: Vect__open_old (open.c:229)
==3496==    by 0x4E57029: Vect_open_old (open.c:415)
==3496==    by 0x402E5F: main (main.c:81)
==3496==
==3496==
==3496== 40,008 bytes in 1 blocks are still reachable in loss record 9 of 21
==3496==    at 0x4C214A1: realloc (vg_replace_malloc.c:429)
==3496==    by 0x5D4D0A8: dig_alloc_nodes (struct_alloc.c:99)
==3496==    by 0x5D46D50: dig_add_node (plus_node.c:116)
==3496==    by 0x5D461D1: add_line (plus_line.c:55)
==3496==    by 0x5D46379: dig_add_line (plus_line.c:114)
==3496==    by 0x4E3CB9B: Vect_build_nat (build_nat.c:538)
==3496==    by 0x4E3AD22: Vect_build_partial (build.c:134)
==3496==    by 0x4E3AC15: Vect_build (build.c:55)
==3496==    by 0x40314C: main (main.c:132)
==3496==
==3496==
==3496== 223,200 bytes in 558 blocks are possibly lost in loss record 10 of 21
==3496==    at 0x4C1F144: calloc (vg_replace_malloc.c:397)
==3496==    by 0x5D3F976: dig__alloc_space (allocation.c:81)
==3496==    by 0x5D4D415: dig_alloc_points (struct_alloc.c:248)
==3496==    by 0x4E4F3CA: Vect_copy_xyz_to_pnts (line.c:118)
==3496==    by 0x404F16: report (visibility.c:219)
==3496==    by 0x404C70: handle (visibility.c:176)
==3496==    by 0x4050E7: construct_visibility (visibility.c:278)
==3496==    by 0x4030EF: main (main.c:125)
==3496==
==3496==
==3496== 248,016 bytes in 5,167 blocks are still reachable in loss
record 11 of 21
==3496==    at 0x4C2136E: malloc (vg_replace_malloc.c:207)
==3496==    by 0x5D4CF59: dig_alloc_node (struct_alloc.c:44)
==3496==    by 0x5D46D93: dig_add_node (plus_node.c:123)
==3496==    by 0x5D461D1: add_line (plus_line.c:55)
==3496==    by 0x5D46379: dig_add_line (plus_line.c:114)
==3496==    by 0x4E3CB9B: Vect_build_nat (build_nat.c:538)
==3496==    by 0x4E3AD22: Vect_build_partial (build.c:134)
==3496==    by 0x4E3AC15: Vect_build (build.c:55)
==3496==    by 0x40314C: main (main.c:132)
==3496==
==3496==
==3496== 449,309 bytes in 66 blocks are still reachable in loss record
12 of 21
==3496==    at 0x4C2136E: malloc (vg_replace_malloc.c:207)
==3496==    by 0x529603E: G__malloc (alloc.c:41)
==3496==    by 0x52CE929: G_store (store.c:36)
==3496==    by 0x52C29D9: G_set_program_name (progrm_nme.c:52)
==3496==    by 0x52AEAD2: G__gisinit (gisinit.c:51)
==3496==    by 0x402CD7: main (main.c:42)
==3496==
==3496==
==3496== 2,645,144 bytes in 4,491 blocks are still reachable in loss
record 13 of 21
==3496==    at 0x4C214A1: realloc (vg_replace_malloc.c:429)
==3496==    by 0x5D4CFF9: dig_node_alloc_line (struct_alloc.c:72)
==3496==    by 0x5D46B28: dig_node_add_line (plus_node.c:56)
==3496==    by 0x5D46079: add_line (plus_line.c:44)
==3496==    by 0x5D46379: dig_add_line (plus_line.c:114)
==3496==    by 0x4E3CB9B: Vect_build_nat (build_nat.c:538)
==3496==    by 0x4E3AD22: Vect_build_partial (build.c:134)
==3496==    by 0x4E3AC15: Vect_build (build.c:55)
==3496==    by 0x40314C: main (main.c:132)
==3496==
==3496==
==3496== 2,645,144 bytes in 4,491 blocks are still reachable in loss
record 14 of 21
==3496==    at 0x4C214A1: realloc (vg_replace_malloc.c:429)
==3496==    by 0x5D4D033: dig_node_alloc_line (struct_alloc.c:77)
==3496==    by 0x5D46B28: dig_node_add_line (plus_node.c:56)
==3496==    by 0x5D4622F: add_line (plus_line.c:64)
==3496==    by 0x5D46379: dig_add_line (plus_line.c:114)
==3496==    by 0x4E3CB9B: Vect_build_nat (build_nat.c:538)
==3496==    by 0x4E3AD22: Vect_build_partial (build.c:134)
==3496==    by 0x4E3AC15: Vect_build (build.c:55)
==3496==    by 0x40314C: main (main.c:132)
==3496==
==3496==
==3496== 2,648,008 bytes in 1 blocks are still reachable in loss
record 15 of 21
==3496==    at 0x4C214A1: realloc (vg_replace_malloc.c:429)
==3496==    by 0x5D4D15B: dig_alloc_lines (struct_alloc.c:133)
==3496==    by 0x5D46344: dig_add_line (plus_line.c:110)
==3496==    by 0x4E3CB9B: Vect_build_nat (build_nat.c:538)
==3496==    by 0x4E3AD22: Vect_build_partial (build.c:134)
==3496==    by 0x4E3AC15: Vect_build (build.c:55)
==3496==    by 0x40314C: main (main.c:132)
==3496==
==3496==
==3496== 4,020,168 bytes in 3 blocks are still reachable in loss
record 16 of 21
==3496==    at 0x4C214A1: realloc (vg_replace_malloc.c:429)
==3496==    by 0x5296148: G__realloc (alloc.c:111)
==3496==    by 0x52A4EB2: set_env (env.c:156)
==3496==    by 0x52A4C44: read_env (env.c:104)
==3496==    by 0x52A54CE: G__getenv (env.c:317)
==3496==    by 0x52A5410: G_getenv (env.c:271)
==3496==    by 0x52B36A0: G_location (location.c:63)
==3496==    by 0x52B36B8: G__location_path (location.c:78)
==3496==    by 0x52B3644: G_location_path (location.c:41)
==3496==    by 0x52AEB0B: G__gisinit (gisinit.c:57)
==3496==    by 0x402CD7: main (main.c:42)
==3496==
==3496==
==3496== 7,937,917 (7,937,869 direct, 48 indirect) bytes in 330,646
blocks are definitely lost in loss record 17 of 21
==3496==    at 0x4C2136E: malloc (vg_replace_malloc.c:207)
==3496==    by 0x529603E: G__malloc (alloc.c:41)
==3496==    by 0x4E3E213: Vect__new_cats_struct (cats.c:62)
==3496==    by 0x4E3E1C4: Vect_new_cats_struct (cats.c:44)
==3496==    by 0x404EB4: report (visibility.c:212)
==3496==    by 0x404B61: handle (visibility.c:164)
==3496==    by 0x4050E7: construct_visibility (visibility.c:278)
==3496==    by 0x4030EF: main (main.c:125)
==3496==
==3496==
==3496== 26,517,440 bytes in 331,468 blocks are still reachable in
loss record 18 of 21
==3496==    at 0x4C2136E: malloc (vg_replace_malloc.c:207)
==3496==    by 0x5D4D0F9: dig_alloc_line (struct_alloc.c:114)
==3496==    by 0x5D45F40: add_line (plus_line.c:27)
==3496==    by 0x5D46379: dig_add_line (plus_line.c:114)
==3496==    by 0x4E3CB9B: Vect_build_nat (build_nat.c:538)
==3496==    by 0x4E3AD22: Vect_build_partial (build.c:134)
==3496==    by 0x4E3AC15: Vect_build (build.c:55)
==3496==    by 0x40314C: main (main.c:132)
==3496==
==3496==
==3496== 407,100,768 (10,579,968 direct, 396,520,800 indirect) bytes
in 330,624 blocks are definitely lost in loss record 19 of 21
==3496==    at 0x4C2136E: malloc (vg_replace_malloc.c:207)
==3496==    by 0x4E4F2F2: Vect__new_line_struct (line.c:69)
==3496==    by 0x4E4F2A8: Vect_new_line_struct (line.c:59)
==3496==    by 0x404EAB: report (visibility.c:211)
==3496==    by 0x404B61: handle (visibility.c:164)
==3496==    by 0x4050E7: construct_visibility (visibility.c:278)
==3496==    by 0x4030EF: main (main.c:125)
==3496==
==3496==
==3496== 34,601,984 bytes in 67,582 blocks are still reachable in loss
record 20 of 21
==3496==    at 0x4C2136E: malloc (vg_replace_malloc.c:207)
==3496==    by 0x5F545D6: RTreeNewNode (node.c:49)
==3496==    by 0x5F56AF6: RTreeSplitNode (split_q.c:313)
==3496==    by 0x5F54E52: RTreeAddBranch (node.c:201)
==3496==    by 0x5F53BA3: RTreeInsertRect2 (index.c:121)
==3496==    by 0x5F5398A: RTreeInsertRect2 (index.c:102)
==3496==    by 0x5F5398A: RTreeInsertRect2 (index.c:102)
==3496==    by 0x5F5398A: RTreeInsertRect2 (index.c:102)
==3496==    by 0x5F5398A: RTreeInsertRect2 (index.c:102)
==3496==    by 0x5F5398A: RTreeInsertRect2 (index.c:102)
==3496==    by 0x5F5398A: RTreeInsertRect2 (index.c:102)
==3496==    by 0x5F53D81: RTreeInsertRect1 (index.c:162)
==3496==
==3496==
==3496== 396,516,048 bytes in 991,294 blocks are indirectly lost in
loss record 21 of 21
==3496==    at 0x4C1F144: calloc (vg_replace_malloc.c:397)
==3496==    by 0x5D3F976: dig__alloc_space (allocation.c:81)
==3496==    by 0x5D4D3C9: dig_alloc_points (struct_alloc.c:239)
==3496==    by 0x4E4F3CA: Vect_copy_xyz_to_pnts (line.c:118)
==3496==    by 0x404F16: report (visibility.c:219)
==3496==    by 0x404C70: handle (visibility.c:176)
==3496==    by 0x4050E7: construct_visibility (visibility.c:278)
==3496==    by 0x4030EF: main (main.c:125)
==3496==
==3496== LEAK SUMMARY:
==3496==    definitely lost: 18,519,885 bytes in 661,274 blocks.
==3496==    indirectly lost: 396,520,848 bytes in 991,300 blocks.
==3496==    possibly lost: 223,872 bytes in 581 blocks.
==3496==    still reachable: 73,888,097 bytes in 414,720 blocks.
==3496==    suppressed: 0 bytes in 0 blocks.

Looks like some memory leak?
E.g.,
data_structures.c:    stack = G_malloc(size * sizeof(struct Point));

but there is no G_free(stack).

In visibility.c I also see two malloc() calls instead of G_malloc().

Markus


More information about the grass-dev mailing list