Skip to content

Commit 97c09c5

Browse files
committed
segfault fix for Connect()
1 parent 3b73ec3 commit 97c09c5

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/node_snap7_client.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,9 @@ namespace node_snap7{
255255
NanReturnValue(NanNew<v8::Boolean>(s7client->snap7Client->Connect() == 0));
256256
}
257257
else{
258+
char* address = new char(0);
258259
NanCallback *callback = new NanCallback(args[0].As<v8::Function>());
259-
NanAsyncQueueWorker(new ConnectionWorker(callback, s7client, "", 0, 0));
260+
NanAsyncQueueWorker(new ConnectionWorker(callback, s7client, address, 0, 0));
260261
NanReturnUndefined();
261262
}
262263
}
@@ -733,15 +734,16 @@ namespace node_snap7{
733734
}
734735

735736
if (!args[1]->IsFunction()){
736-
TS7BlocksOfType BlockList;
737-
int BlockNum = sizeof(BlockList) / sizeof(*BlockList);
738-
739-
int returnValue = s7client->snap7Client->ListBlocksOfType(args[0]->Uint32Value(), &BlockList, &BlockNum);
737+
int BlockNum = sizeof(TS7BlocksOfType) / sizeof(PS7BlocksOfType);
738+
PS7BlocksOfType BlockList = new TS7BlocksOfType[BlockNum];
739+
740+
int returnValue = s7client->snap7Client->ListBlocksOfType(args[0]->Uint32Value(), BlockList, &BlockNum);
740741

741742
v8::Local<v8::Array> block_list = NanNew<v8::Array>(BlockNum);
742743
for (int i = 0; i < BlockNum; i++) {
743-
block_list->Set(i, NanNew<v8::Integer>(BlockList[i]));
744+
block_list->Set(i, NanNew<v8::Integer>(*BlockList[i]));
744745
}
746+
delete[] BlockList;
745747

746748
if (returnValue == 0)
747749
NanReturnValue(block_list);

0 commit comments

Comments
 (0)