[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Heap Corruption
From: |
Adrian Vogelsgesang |
Subject: |
Re: Heap Corruption |
Date: |
Thu, 10 Dec 2020 08:24:37 +0000 |
Hi Jot,
skimming over your code, I couldn’t find anything particularly wrong or
suspicious…
If you could post a self-contained repro that would me to follow your steps and
maybe debug this in more depth.
In case it requires more than a few files, maybe you could upload your code to
Github and share the link here.
Heap corruption is always mean to debug…
It could be that your heap was already corrupted way earlier, but only the
“delete” notices that corruption which occurred for a totally independent
reason.
In general, I would recommend to enable address sanitizer in your compile
(“-fsanitize=address” flag in both gcc & clang; see
https://clang.llvm.org/docs/AddressSanitizer.html) which should point you to
the exact line of code which causes the corruption.
Furthermore, I would in general recommend to always use
`std::unique_ptr`/`std::make_unique` over “new” and “delete”.
Cheers,
Adrian
From: help-bison <help-bison-bounces+avogelsgesang=tableau.com@gnu.org>
Date: Thursday, 10. December 2020 at 03:23
To: help-bison@gnu.org <help-bison@gnu.org>
Subject: Heap Corruption
I'm at a loss.
I have set up a c++ scanner/parser to run on the command line (windows).
The parser corrupts the heap. I have no clue at all what I am doing wrong.
I think I have set everything up correctly and everything compiles without
any issue. I have defined a parser class, a lexer class, and my own driver
class. This driver class is passed to the lexer and parser. My .l and .y
files are copies of what I have already set up in a DLL - which does not
have this issue.
I am not sure what to post (unnecessary clutter?) but below is what I
believe is a confirmation of my issue.
Note: I simply construct the parser and delete it immediately - and get a
heap corruption error.Tracing thru the code, it looks like it is simply
establishing the stack (when creating the Parser).
Anyone have a similar issue? Any ideas are welcome.
I'll post anything anybody wants to look at.
Thanks
//----------------
class Driver
{
protected:
gen::Parser* pParser;
gen::Scanner* pScanner;
ParseResults* pResult;
public:
Driver()
{
pResult = new ParseResults; // Test ok
delete pResult; // Test ok
pResult = new ParseResults;
pScanner = new gen::Scanner(this); // Test ok
delete pScanner; // Test ok
pScanner = new gen::Scanner(this);
pParser = new gen::Parser(this); // Test ok
delete pParser; // Test <= FAIL: Heap Corruption
pParser = new gen::Parser(this);
}
virtual ~Driver()
{
delete pScanner;
delete pParser;
delete pResult;
}
gen::Parser* getParser() const { return pParser; }
gen::Scanner* getScanner() const { return pScanner; }
ParseResults* getResult() const { return pResult; }
};
- Heap Corruption, Jot Dot, 2020/12/09
- Re: Heap Corruption,
Adrian Vogelsgesang <=