-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak in C parser #347
Comments
I avoid this issue by using the other edition Before that, I need convert the C-string into a |
Maybe you didn't mean this literally, but a simple
This seems to be the correct use pattern, see also the definition of (Maybe there is a better reference for using the |
Yep, I did that. In my initial test, the AST tree only contains a single root node, And it still says 16KB memory leaked. The real code traverses AST tree and free all of them. source code is here, C parser is called by Rust via FFI, it is the same how we call it from C. Let me put it simple
So I convert a |
Thanks for getting back to me @wangjia184! The problem is that the generated Not calling |
Note to myself: Here is a modified driver #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Parser.h"
#include "Printer.h"
#include "Absyn.h"
void usage(void) {
printf("usage: Call with one of the following argument combinations:\n");
printf("\t--help\t\tDisplay this help message.\n");
printf("\t(text)\t\tParse text verbosely.\n");
printf("\t-s (text)\tSilent mode. Parse text silently.\n");
}
int main(int argc, char ** argv)
{
Exp parse_tree;
int quiet = 0;
char *text = NULL;
if (argc > 1) {
if (strcmp(argv[1], "-s") == 0) {
quiet = 1;
if (argc > 2) {
text = argv[2];
}
} else {
text = argv[1];
}
}
if (!text) {
text = "1 + 2 * 3";
/* usage(); */
/* exit(1); */
}
parse_tree = psExp(text);
if (parse_tree)
{
printf("\nParse Successful!\n");
if (!quiet) {
printf("\n[Abstract Syntax]\n");
printf("%s\n\n", showExp(parse_tree));
printf("[Linearized Tree]\n");
printf("%s\n\n", printExp(parse_tree));
}
return 0;
}
return 1;
} This is the
TODO: add tests that check for memory leaks in the testsuite. |
@wangjia184: The release of 2.9.2 will probably be in a few months only, so if you rely on this fix, please install the Upstream issue (flex): westes/flex#479 |
There are still some space leaks, e.g. in tests
|
Also: build Skeleton.o which currently fails for 266_define. The valgrind check seems to randomly fail when running the testsuite, but no definite leaks are detected when running a test case manually. Thus, I leave this test off, as it is not reliable.
Well, dunno, the memory leaks show only (and non-deterministically) when running the testsuite, not when running the tests individually. |
BNFC version 2.9.1
Here is the code generated by BNFC
I successfully call this method, and then called
free()
on the returned pointer.but valgrind says there is 16KB memory leaked.
The leak is from
mylang__create_buffer
(yy_create_buffer
) line 2047 below.It is strange that
psProc()
did callmylang__delete_buffer
(yy_delete_buffer
) .Is this a bug? Or I used it incorrectly?
The text was updated successfully, but these errors were encountered: