Skip to content
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

Possible double free of RenderableManager::Builder. Detected under wasm #871

Closed
ncoder opened this issue Feb 23, 2019 · 3 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@ncoder
Copy link

ncoder commented Feb 23, 2019

Describe the bug
Possible double-free situation in RenderableManager::Builder.
A bit early to tell, but the combination of using default copy constructors with a constructor/destructor that does a new/delete is usually a problem.

See RenderableManager.cpp

using BuilderType = RenderableManager;
BuilderType::Builder::Builder(size_t count) noexcept
        : BuilderBase<RenderableManager::BuilderDetails>(count) {
    mImpl->mEntries = new Entry[count];
}
BuilderType::Builder::~Builder() noexcept {
    delete [] mImpl->mEntries;
}
BuilderType::Builder::Builder(BuilderType::Builder&& rhs) noexcept = default;
BuilderType::Builder& BuilderType::Builder::operator=(BuilderType::Builder&& rhs) noexcept = default;

To Reproduce
Latest master (e9430dd)

Running triangle.html, if fails to run in debug.
With extra flags turned on, we get more data:

Adding these options to web/filament-js/CMakeLists.txt
set(LOPTS "${LOPTS} -s ASSERTIONS=1")
set(LOPTS "${LOPTS} -s SAFE_HEAP=1")
set(LOPTS "${LOPTS} -s DEMANGLE_SUPPORT=1")

Running out/cmake-webgl-debug/web/samples/triangle.html:

filament.js:1820 wasm streaming compile failed: abort("segmentation fault") at Error
at jsStackTrace (http://localhost:8080/filament.js:1146:13)
at stackTrace (http://localhost:8080/filament.js:1163:12)
at abort (http://localhost:8080/filament.js:13147:44)
at segfault (http://localhost:8080/filament.js:481:3)
at SAFE_HEAP_LOAD_i32_4_U_4 (wasm-function[8735]:29)
at __ZN8filament17RenderableManager7BuilderD2Ev [filament::RenderableManager::Builder::~Builder()] (wasm-function[3357]:47)
at _ZN10emscripten8internal7InvokerIN8filament17RenderableManager7BuilderEJiEE6invokeEPFS4_iEi [emscripten::internal::Invoker<filament::RenderableManager::Builder, int>::invoke(filament::RenderableManager::Builder (*)(int), int)] (wasm-function[1060]:80)
at dynCall_iii (wasm-function[8591]:16)
at dynCall_iii_396 (eval at makeDynCaller (http://localhost:8080/filament.js:6300:19), :4:12)
at Function.RenderableManager$Builder [as Builder] (eval at new
(http://localhost:8080/filament.js:6496:27), :8:10)

Expected behavior
example should run.

Desktop (please complete the following information):
This is build and run on Mac + Chrome.
WebGL backend.

@romainguy
Copy link
Collaborator

@pixelflinger

@pixelflinger
Copy link
Collaborator

Yeah, that looks like a bug, when the && ctor is used. Good catch, thanks!

@pixelflinger pixelflinger added the bug Something isn't working label Feb 25, 2019
@prideout
Copy link
Contributor

Thanks for looking at this Mathias.

pixelflinger added a commit that referenced this issue Feb 25, 2019
The move ctor wasn't implemented properly. We actually fix this by
using a std::vector<> instead of a raw allocation for storing entries.
This std::vector<> is never reallocated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants