jplevyak / dparser

A Scannerless GLR parser/parser generater.
https://github.com/jplevyak/dparser
BSD 3-Clause "New" or "Revised" License
105 stars 14 forks source link

dparser memory leak #17

Closed mattfidler closed 4 years ago

mattfidler commented 4 years ago

There is a small memory leak with bad syntax. Here is a reproducible example.

  1. Replace the sample.g with the grammar here
  2. Make the dparser package
  3. Create the following invalid syntax file:
    # comment, just to show error in line 3
    d/dt(y) = -ka;
    C1 = /y;

I name it bad.txt

From the terminal you can see some of the memory is lost:

matt@localhost ~/src/dparser $ valgrind ./sample_parser bad.txt
==2465== Memcheck, a memory error detector
==2465== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2465== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==2465== Command: ./sample_parser bad.txt
==2465== 
:3: syntax error after '='
fatal error, '' line 3
==2465== 
==2465== HEAP SUMMARY:
==2465==     in use at exit: 11,312 bytes in 37 blocks
==2465==   total heap usage: 403 allocs, 366 frees, 288,690 bytes allocated
==2465== 
==2465== LEAK SUMMARY:
==2465==    definitely lost: 136 bytes in 1 blocks
==2465==    indirectly lost: 11,176 bytes in 36 blocks
==2465==      possibly lost: 0 bytes in 0 blocks
==2465==    still reachable: 0 bytes in 0 blocks
==2465==         suppressed: 0 bytes in 0 blocks
==2465== Rerun with --leak-check=full to see details of leaked memory
==2465== 
==2465== For lists of detected and suppressed errors, rerun with: -s
==2465== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
jplevyak commented 4 years ago

Fixed. https://github.com/jplevyak/dparser/commit/25ff3a89ae72afc9984e743055b18e9630d9314b

mattfidler commented 4 years ago

Thanks!