Skip to content

Commit

Permalink
fix crash at port open (#1772)
Browse files Browse the repository at this point in the history
  • Loading branch information
nowakpl authored and reconbot committed Jan 11, 2019
1 parent 8fc58a4 commit 415891c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions packages/bindings/src/serialport.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,17 @@ struct OpenBaton : public Nan::AsyncResource {
#endif
};

struct ConnectionOptionsBaton : public Nan::AsyncResource {
ConnectionOptionsBaton() :
AsyncResource("node-serialport:ConnectionOptionsBaton"), errorString() {}
struct ConnectionOptions {
ConnectionOptions() : errorString() {}
char errorString[ERROR_STRING_SIZE];
Nan::Callback callback;
int fd = 0;
int baudRate = 0;
};
struct ConnectionOptionsBaton : ConnectionOptions, Nan::AsyncResource {
ConnectionOptionsBaton() :
AsyncResource("node-serialport:ConnectionOptionsBaton") {}
Nan::Callback callback;
};

struct SetBaton : public Nan::AsyncResource {
SetBaton() : AsyncResource("node-serialport:SetBaton"), errorString() {}
Expand Down Expand Up @@ -131,5 +134,5 @@ struct VoidBaton : public Nan::AsyncResource {
};

int setup(int fd, OpenBaton *data);
int setBaudRate(ConnectionOptionsBaton *data);
int setBaudRate(ConnectionOptions *data);
#endif // PACKAGES_SERIALPORT_SRC_SERIALPORT_H_
4 changes: 2 additions & 2 deletions packages/bindings/src/serialport_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void EIO_Open(uv_work_t* req) {
data->result = fd;
}

int setBaudRate(ConnectionOptionsBaton *data) {
int setBaudRate(ConnectionOptions *data) {
// lookup the standard baudrates from the table
int baudRate = ToBaudConstant(data->baudRate);
int fd = data->fd;
Expand Down Expand Up @@ -281,7 +281,7 @@ int setup(int fd, OpenBaton *data) {
}

// Copy the connection options into the ConnectionOptionsBaton to set the baud rate
ConnectionOptionsBaton* connectionOptions = new ConnectionOptionsBaton();
ConnectionOptions* connectionOptions = new ConnectionOptions();
connectionOptions->fd = fd;
connectionOptions->baudRate = data->baudRate;

Expand Down

0 comments on commit 415891c

Please sign in to comment.