Skip to content

Commit

Permalink
Merge pull request #34 from toyoge009/fix_readbaton
Browse files Browse the repository at this point in the history
Fixed a problem that segmentation fault occurs when ReadWorker baton is overwitten.
  • Loading branch information
thomaschaaf authored Aug 20, 2019
2 parents af8f57f + 3e7bcb3 commit db26292
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ftdi",
"version": "1.2.2",
"version": "1.2.3",
"description": "FTDI bindings for Node.js",
"main": "index.js",
"dependencies": {
Expand Down
8 changes: 5 additions & 3 deletions src/ftdi_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ class ReadWorker : public Nan::AsyncWorker {
// here, so everything we need for input and output
// should go on `this`.
void Execute () {
baton = new ReadBaton_t();
baton = &batonEntity;
baton->length = 0;
baton->data = NULL;
status = FtdiDevice::ReadDataAsync(device, baton);
}

Expand Down Expand Up @@ -203,7 +205,7 @@ class ReadWorker : public Nan::AsyncWorker {
callback->Call(2, argv);
}

if(baton->length != 0)
if(baton->data != NULL)
{
delete baton->data;
baton->length = 0;
Expand All @@ -221,13 +223,13 @@ class ReadWorker : public Nan::AsyncWorker {
AsyncQueueWorkerPersistent(this);
}

delete baton;
};

private:
FT_STATUS status;
FtdiDevice* device;
ReadBaton_t* baton;
ReadBaton_t batonEntity;
};

FT_STATUS FtdiDevice::ReadDataAsync(FtdiDevice* device, ReadBaton_t* baton)
Expand Down

0 comments on commit db26292

Please sign in to comment.