copc-uaopen62541

OPC-UA Function of "UA_ReadRequest_deleteMembers" Error Problem


Hello Everyone i have one question

I Using OPC-UA for client, I have some problem

This is Problem code

UA_ReadRequest requestPos;
UA_ReadRequest_init(&requestPos);
UA_ReadValueId idPos;
UA_ReadValueId_init(&idPos);
idPos.attributeId = UA_ATTRIBUTEID_VALUE;
idPos.nodeId = UA_NODEID_STRING(6, (char*)"::AsGlobalPV:gMotionPos");
requestPos.nodesToRead = &idPos;
requestPos.nodesToReadSize = 1;

UA_ReadResponse responsePos = UA_Client_Service_read(client, requestPos);

UA_ReadRequest_deleteMembers(&requestPos);

I want to clear UA_ReadRequest requestPos;, so I use UA_ReadRequest_deleteMembers(&requestPos);, but compiler said: "****.exe caused a breakpoint. Occur ". I can't understand this error.

enter image description here


Solution

  • You have created a non-owning string nodeid. The delete members will free the memory used, even though it's not owned resulting in a memory corruption.

    Replace the UA_NODEID_STRING() with UA_NODEID_STRING_ALLOC().