Skip to content

Bug: Dangling reference captures in WASM lambda callbacks #53

Description

Platform: WebAssembly only
Files: connector.cpp:368, auxconnector.cpp:245

What's wrong

wasmOpenProof and wasmImportProof both capture pointer parameters by reference in async lambdas. On WASM, QFileDialog::getOpenFileContent returns immediately and the callback fires later, by then the stack frame is gone and all captured references are dangling. This is use-after-free / undefined behaviour.

// connector.cpp:368
auto fileContentReady = [&open, this, &gls](...) { ... };  // &open, &gls dangle after return

// auxconnector.cpp:245
auto fileContentReady = [this, &c, &pd, &pm](...) { ... }; // &c, &pd, &pm dangle after return

Fix

Capture by value: these are already pointers so copying is just 8 bytes each.

// connector.cpp
auto fileContentReady = [open, this, gls](...) { ... };

// auxconnector.cpp
auto fileContentReady = [this, c, pd, pm](...) { ... };

&openopen, &glsgls, &cc, &pdpd, &pmpm.

The pointed-to objects are long-lived Qt UI models that outlive any file dialog, so capturing pointer values is safe.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions