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

Fix heap corruption issue on windows #623

Merged
merged 1 commit into from
Nov 9, 2015

Conversation

kunalspathak
Copy link
Contributor

In EIO_AfterWatchPort, serialport creates a v8::ArrayBuffer using Nan::NewBuffer() API which creates v8::ArrayBuffer with ArrayBufferCreationMode::kInternalized mode. This means that v8 engine takes the responsibility of freeing the external buffer passed to the v8::ArrayBuffer.
However EIO_AfterWatchPort deletes and frees the buffer at the end of method.

cleanup:
    delete data;
    delete req;

When ArrayBuffer object is garbage collected, it tries to free the external buffer passed to it, but since it is already freed, we get heap corruption and the stack looks pretty much like one shown in #617.
The repro for this is inconsistent as it depends on state of memory at the time of GC, but with Microsoft's AppVerifier tool, there is a consistent repro for this.

The fix is to pass FinalizerCallback to Nan::NewBuffer() API that will internally create the ArrayBuffer in ArrayBufferCreationMode::kExternalized mode. This means that engine won't take the responsibility of freeing the buffer and when collection of arraybuffer happens, it will call the callback which will free the buffer.

Fixes #617, #618

Fix the heap corruption issue in serialport causing random access violation failures.
@ghost
Copy link

ghost commented Nov 6, 2015

Just checked out this changes. They actually fix the problem with crashing under Windows.

@techninja
Copy link

Yep, just tested, this fixes a pretty nasty anonymous crash in Electron as well!

jacobrosenthal added a commit that referenced this pull request Nov 9, 2015
Fix heap corruption issue on windows
@jacobrosenthal jacobrosenthal merged commit e9b8440 into serialport:master Nov 9, 2015
reconbot pushed a commit that referenced this pull request Jul 24, 2018
Fix heap corruption issue on windows
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Versions 2.x crashes with Windows 7 x64
3 participants