[1379] Fix memory leaks on exceptions

See #1379

  * fix memory leaks;
  * sync base.c with parser.c