cocom-org / msta

yacc-compatible syntax description translator with additional features like EBNF, producing faster parsers than bison
5 stars 0 forks source link

Memory issues detected by valgrind #1

Open mingodad opened 2 years ago

mingodad commented 2 years ago

On a fresh build of this project and executing it under valgrind gives this result:

valgrind ./msta c5.y 
==16580== Memcheck, a memory error detector
==16580== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==16580== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==16580== Command: ./msta c5.y
==16580== 
==16580== Conditional jump or move depends on uninitialised value(s)
==16580==    at 0x450CB7: malloc_hook_ini (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x4B186A: _dl_get_origin (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x47E45E: _dl_non_dynamic_init (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x47FAD0: __libc_init_first (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x431D90: (below main) (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580== 
==16580== Conditional jump or move depends on uninitialised value(s)
==16580==    at 0x450DA9: malloc_hook_ini (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x4B186A: _dl_get_origin (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x47E45E: _dl_non_dynamic_init (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x47FAD0: __libc_init_first (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x431D90: (below main) (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580== 
==16580== Conditional jump or move depends on uninitialised value(s)
==16580==    at 0x44E813: _int_malloc (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x4506D4: tcache_init.part.4 (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x450DB8: malloc_hook_ini (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x4B186A: _dl_get_origin (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x47E45E: _dl_non_dynamic_init (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x47FAD0: __libc_init_first (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x431D90: (below main) (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580== 
==16580== Conditional jump or move depends on uninitialised value(s)
==16580==    at 0x44CFC5: _int_free (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x44FB24: _int_realloc (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x452A30: realloc_hook_ini (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x428F83: _VLO_tailor_function (vlobject.c:74)
==16580==    by 0x42B2E4: start_command_line_processing (commline.c:253)
==16580==    by 0x400753: main (main.c:432)
==16580== 
==16580== Conditional jump or move depends on uninitialised value(s)
==16580==    at 0x44CFC5: _int_free (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x44FB24: _int_realloc (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x452E41: realloc (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x428F83: _VLO_tailor_function (vlobject.c:74)
==16580==    by 0x42B2E4: start_command_line_processing (commline.c:253)
==16580==    by 0x400753: main (main.c:432)
==16580== 
==16580== Conditional jump or move depends on uninitialised value(s)
==16580==    at 0x451BDF: free (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x4295C2: _OS_delete_function (objstack.c:95)
==16580==    by 0x429F81: output_errors (errors.c:356)
==16580==    by 0x400ED7: main (main.c:708)
==16580== 
  Max look ahead is 1 token
  Real look ahead is 1 token
  1 shift/reduce conflict.
==16580== Conditional jump or move depends on uninitialised value(s)
==16580==    at 0x451BDF: free (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x429E74: finish_errors (errors.c:328)
==16580==    by 0x428ECF: msta_finish (main.c:164)
==16580==    by 0x400EF8: main (main.c:714)
==16580== 
==16580== 
==16580== HEAP SUMMARY:
==16580==     in use at exit: 0 bytes in 0 blocks
==16580==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==16580== 
==16580== All heap blocks were freed -- no leaks are possible
==16580== 
==16580== Use --track-origins=yes to see where uninitialised values come from
==16580== For lists of detected and suppressed errors, rerun with: -s
==16580== ERROR SUMMARY: 55 errors from 7 contexts (suppressed: 0 from 0)
rofl0r commented 2 years ago

you have a proposed fix ?

mingodad commented 2 years ago

Not yet ! I did several tests but didn't got where the problem is right now.

mingodad commented 2 years ago

Looking again I found that after commenting out this line on Makefile.in valgrind doesn't show any invalid memory access anymore:

nodist_msta_SOURCES = yacc.c
CLEANFILES = yacc.c
msta_CFLAGS = -I$(srcdir)/AMMUNITION
#msta_LDFLAGS = -static  #!!!!!<<<<  commenting this line
mingodad commented 2 years ago

Looking again the correct place to comment the offending line is in Makefile.am.

rofl0r commented 2 years ago

it's odd that this would make a difference, except in that valgrind requires dynamic linking to inject its shared libraries overriding malloc and friends... otoh forcing a static build probably isn't that good of an idea; it should be up to the user configuring the build.

mingodad commented 2 years ago

Yes I agree with you, I don't see the point to link the compiler libraries statically by default.

vnmakarov commented 2 years ago

Valgrind can be very rigorous. There are some algorithms which work fine using uninitialized data and valgrind will complaint about this. The classical example is sparse sets https://www.geeksforgeeks.org/sparse-set/