apoch / epoch-language

Home of the Epoch Programming Language Project
Other
72 stars 3 forks source link

Memory::DisposeOneWayBlocks() Will falsely throw exception claiming memory leak #101

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This is against revision rfe570a8e5c0b3da3a0f10e413cb2064410f013d6:

EpochCompiler/Parser/Parser.cpp line 53 - 54:
            ptr.reset(new AST::Program);
            Memory::DisposeOneWayBlocks();

This code can throw because the AST::Program default constructor will invoke 
the default constructor of the std::vector class. The std::vector class can 
allocate memory during its construction, especially as a pre-optimization for 
initial inserts (i.e. given a std::vector v, v.capacity() != 0).

Callstacks that invoke the default AST::Program constructor, note the allocate 
call in each:

    EpochCompiler.dll!Memory::OneWayAllocate(unsigned int bytes)  Line 34   C++
    EpochCompiler.dll!Memory::OneWayAlloc<std::_Container_proxy>::allocate(unsigned int cnt, const void * __formal)  Line 74 + 0xc bytes    C++
    EpochCompiler.dll! ?? :: ?? :: ?? ... truncated ... Line 442 + 0xc bytes    C++
    EpochCompiler.dll! ?? :: ?? :: ?? ()  Line 507 + 0x3f bytes C++
>   EpochCompiler.dll!AST::Program::Program()  Line 55 + 0x2b bytes C++
    EpochCompiler.dll!CompileSession::EmitByteCode()  Line 115 + 0x2b bytes C++

    EpochCompiler.dll!Memory::OneWayAllocate(unsigned int bytes)  Line 34   C++
    EpochCompiler.dll!Memory::OneWayAlloc<std::_Container_proxy>::allocate(unsigned int cnt, const void * __formal)  Line 74 + 0xc bytes    C++
    EpochCompiler.dll! ?? :: ?? :: ?? ... truncated ... Line 442 + 0xc bytes    C++
    EpochCompiler.dll! ?? :: ?? :: ?? ()  Line 507 + 0x3f bytes C++
>   EpochCompiler.dll!AST::Program::Program()  Line 55 + 0x2b bytes C++
    EpochCompiler.dll!Parser::Parse(const std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > & code, const std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > & filename, AST::Program & program)  Line 53 + 0x34 bytes   C++

Fixes:
One possible fix would be to change Parser::Parse to take a reference to a 
pointer to the AST::Program instead of a reference, this would then allow it to 
set the pointer instead of setting a reference. Then the AST::Program creation 
could be delayed till after the Memory::DisposeOneWayBlocks() call.

This is how the attached patch opts to solve the issue.

Original issue reported on code.google.com by ryoohki@gmail.com on 6 Feb 2012 at 9:13

Attachments:

GoogleCodeExporter commented 9 years ago
Fixed auto_ptr issue

Original comment by ryoohki@gmail.com on 6 Feb 2012 at 9:31

Attachments:

GoogleCodeExporter commented 9 years ago
Made changes in rf98413fd4a50fc76c9a8566ba14273123d1077da and 
rb3a3766d0fd3b466c0a6d0c4f2c8016f26ac9fc0

Original comment by ryoohki@gmail.com on 8 Feb 2012 at 2:45