Browse Source

fixed mem leaks

FlorianPalm 10 years ago
parent
commit
0bdfb9f8b3

+ 1 - 0
examples/opcuaServer.c

@@ -79,6 +79,7 @@ int main(int argc, char** argv) {
     parentNodeId.nodeId = UA_NODEIDS[UA_OBJECTSFOLDER];
     UA_Server_addScalarVariableNode(server, &myIntegerName, (void*)&myInteger, &UA_TYPES[UA_INT32],
     		&parentNodeId, (UA_NodeId*)&UA_NODEIDS[UA_ORGANIZES]);
+    UA_QualifiedName_deleteMembers(&myIntegerName);
 
 #ifdef BENCHMARK
     UA_UInt32 nodeCount = 500;

+ 22 - 22
src/server/nodestore/open62541_nodestore_nodemanagement.c

@@ -59,7 +59,6 @@ static UA_Int32 AddReference(open62541NodeStore *nodestore, UA_Node *node,
 	return retval;
 }
 
-
 #define COPY_STANDARDATTRIBUTES do { \
 if(attr.specifiedAttributes & UA_NODEATTRIBUTESMASK_DISPLAYNAME) { \
 vnode->displayName = attr.displayName; \
@@ -75,8 +74,6 @@ if(attr.specifiedAttributes & UA_NODEATTRIBUTESMASK_USERWRITEMASK) \
 vnode->userWriteMask = attr.userWriteMask; \
 } while(0)
 
-
-
 static UA_StatusCode parseVariableNode(UA_ExtensionObject *attributes,
 		UA_Node **new_node, const UA_VTable_Entry **vt) {
 	if (attributes->typeId.identifier.numeric != 357) // VariableAttributes_Encoding_DefaultBinary,357,Object
@@ -144,8 +141,7 @@ static UA_StatusCode parseObjectNode(UA_ExtensionObject *attributes,
 	}
 // now copy all the attributes. This potentially removes them from the decoded attributes.
 	COPY_STANDARDATTRIBUTES;
-	if (attr.specifiedAttributes
-			& UA_NODEATTRIBUTESMASK_EVENTNOTIFIER) {
+	if (attr.specifiedAttributes & UA_NODEATTRIBUTESMASK_EVENTNOTIFIER) {
 		vnode->eventNotifier = attr.eventNotifier;
 	}
 	UA_ObjectAttributes_deleteMembers(&attr);
@@ -171,18 +167,20 @@ static UA_StatusCode parseReferenceTypeNode(UA_ExtensionObject *attributes,
 // now copy all the attributes. This potentially removes them from the decoded attributes.
 	COPY_STANDARDATTRIBUTES;
 
-	if (attr.specifiedAttributes
-			& UA_NODEATTRIBUTESMASK_ISABSTRACT) {
+	if (attr.specifiedAttributes & UA_NODEATTRIBUTESMASK_ISABSTRACT) {
 		vnode->isAbstract = attr.isAbstract;
 	}
-	if (attr.specifiedAttributes
-			& UA_NODEATTRIBUTESMASK_SYMMETRIC) {
+	if (attr.specifiedAttributes & UA_NODEATTRIBUTESMASK_SYMMETRIC) {
 		vnode->symmetric = attr.symmetric;
 	}
-	if (attr.specifiedAttributes
-			& UA_NODEATTRIBUTESMASK_INVERSENAME) {
+	if (attr.specifiedAttributes & UA_NODEATTRIBUTESMASK_INVERSENAME) {
 		vnode->inverseName = attr.inverseName;
 
+		attr.inverseName.text.length = -1;
+		attr.inverseName.text.data = UA_NULL;
+
+		attr.inverseName.locale.length = -1;
+		attr.inverseName.locale.data = UA_NULL;
 	}
 
 	UA_ReferenceTypeAttributes_deleteMembers(&attr);
@@ -208,8 +206,7 @@ static UA_StatusCode parseObjectTypeNode(UA_ExtensionObject *attributes,
 // now copy all the attributes. This potentially removes them from the decoded attributes.
 	COPY_STANDARDATTRIBUTES;
 
-	if (attr.specifiedAttributes
-			& UA_NODEATTRIBUTESMASK_ISABSTRACT) {
+	if (attr.specifiedAttributes & UA_NODEATTRIBUTESMASK_ISABSTRACT) {
 		vnode->isAbstract = attr.isAbstract;
 	}
 	UA_ObjectTypeAttributes_deleteMembers(&attr);
@@ -235,12 +232,10 @@ static UA_StatusCode parseViewNode(UA_ExtensionObject *attributes,
 // now copy all the attributes. This potentially removes them from the decoded attributes.
 	COPY_STANDARDATTRIBUTES;
 
-	if (attr.specifiedAttributes
-			& UA_NODEATTRIBUTESMASK_CONTAINSNOLOOPS) {
+	if (attr.specifiedAttributes & UA_NODEATTRIBUTESMASK_CONTAINSNOLOOPS) {
 		vnode->containsNoLoops = attr.containsNoLoops;
 	}
-	if (attr.specifiedAttributes
-			& UA_NODEATTRIBUTESMASK_EVENTNOTIFIER) {
+	if (attr.specifiedAttributes & UA_NODEATTRIBUTESMASK_EVENTNOTIFIER) {
 		vnode->eventNotifier = attr.eventNotifier;
 	}
 	UA_ViewAttributes_deleteMembers(&attr);
@@ -344,22 +339,26 @@ UA_Int32 open62541NodeStore_AddNodes(const UA_RequestHeader *requestHeader,
 			break;
 		}
 		case UA_NODECLASS_OBJECT: {
-			parseObjectNode(&nodesToAdd[indices[i]].nodeAttributes,&newNode,&newNodeVT);
+			parseObjectNode(&nodesToAdd[indices[i]].nodeAttributes, &newNode,
+					&newNodeVT);
 			newNode->nodeClass = UA_NODECLASS_OBJECT;
 			break;
 		}
 		case UA_NODECLASS_OBJECTTYPE: {
-			parseObjectTypeNode(&nodesToAdd[indices[i]].nodeAttributes,&newNode,&newNodeVT);
+			parseObjectTypeNode(&nodesToAdd[indices[i]].nodeAttributes,
+					&newNode, &newNodeVT);
 			newNode->nodeClass = UA_NODECLASS_OBJECTTYPE;
 			break;
 		}
 		case UA_NODECLASS_REFERENCETYPE: {
-			parseReferenceTypeNode(&nodesToAdd[indices[i]].nodeAttributes,&newNode,&newNodeVT);
+			parseReferenceTypeNode(&nodesToAdd[indices[i]].nodeAttributes,
+					&newNode, &newNodeVT);
 			newNode->nodeClass = UA_NODECLASS_REFERENCETYPE;
 			break;
 		}
 		case UA_NODECLASS_VARIABLE: {
-			parseVariableNode(&nodesToAdd[indices[i]].nodeAttributes,&newNode,&newNodeVT);
+			parseVariableNode(&nodesToAdd[indices[i]].nodeAttributes, &newNode,
+					&newNodeVT);
 			newNode->nodeClass = UA_NODECLASS_VARIABLE;
 			break;
 		}
@@ -384,6 +383,7 @@ UA_Int32 open62541NodeStore_AddNodes(const UA_RequestHeader *requestHeader,
 				&newNode->browseName);
 
 		UA_AddReferencesItem addRefItem;
+		UA_AddReferencesItem_init(&addRefItem);
 		addRefItem.isForward = UA_TRUE;
 		addRefItem.referenceTypeId = nodesToAdd[indices[i]].referenceTypeId;
 		addRefItem.sourceNodeId = nodesToAdd[indices[i]].parentNodeId.nodeId;
@@ -402,7 +402,7 @@ UA_Int32 open62541NodeStore_AddNodes(const UA_RequestHeader *requestHeader,
 			open62541NodeStore_AddReferences(requestHeader, &addRefItem, &ind,
 					indSize, &result, &diagnosticInfo);
 		}
-
+		UA_AddReferencesItem_deleteMembers(&addRefItem);
 	}
 	return UA_STATUSCODE_GOOD;
 }

+ 31 - 0
src/server/ua_namespace.c

@@ -0,0 +1,31 @@
+/*
+ * ua_namespace.c
+ *
+ *  Created on: Nov 6, 2014
+ *      Author: opcua
+ */
+#include "ua_namespace.h"
+#include "ua_nodestore_interface.h"
+
+
+UA_Namespace *UA_Namespace_new()
+{
+	UA_Namespace *n = UA_alloc(sizeof(UA_Namespace));
+    if(n) UA_Namespace_init(n);
+    return n;
+}
+
+void UA_Namespace_init(UA_Namespace *namespace)
+{
+	namespace->index = 0;
+	namespace->nodeStore = UA_NULL;
+	UA_String_init(&namespace->url);
+}
+void UA_Namespace_delete(UA_Namespace *namespace){
+	UA_Namespace_deleteMembers(namespace);
+	UA_free(namespace);
+}
+void UA_Namespace_deleteMembers(UA_Namespace *namespace){
+	UA_String_deleteMembers(&namespace->url);
+	UA_NodeStoreInterface_delete(namespace->nodeStore);
+}

+ 26 - 0
src/server/ua_namespace.h

@@ -0,0 +1,26 @@
+/*
+ * ua_namespace.h
+ *
+ *  Created on: Nov 6, 2014
+ *      Author: opcua
+ */
+
+#ifndef UA_NAMESPACE_H_
+#define UA_NAMESPACE_H_
+#include "ua_server.h"
+#include "ua_util.h"
+#include "ua_statuscodes.h"
+
+typedef struct UA_Namespace
+{
+	UA_UInt16 index;
+	UA_String url;
+	UA_NodeStoreInterface *nodeStore;
+}UA_Namespace;
+
+UA_Namespace *UA_Namespace_new();
+void UA_Namespace_init(UA_Namespace *namespace);
+void UA_Namespace_delete(UA_Namespace *namespace);
+void UA_Namespace_deleteMembers(UA_Namespace *namespace);
+
+#endif /* UA_NAMESPACE_H_ */

+ 0 - 2
src/server/ua_namespace_manager.c

@@ -29,8 +29,6 @@ void UA_NamespaceManager_deleteMembers(UA_NamespaceManager *namespaceManager)
 	struct namespace_list_entry *current = LIST_FIRST(&namespaceManager->namespaces);
     while(current) {
         LIST_REMOVE(current, pointers);
-        if(current->namespace.nodeStore != UA_NULL)
-            current->namespace.nodeStore = UA_NULL; // the channel is no longer attached to a session
         UA_Namespace_deleteMembers(&current->namespace);
         UA_free(current);
         current = LIST_FIRST(&namespaceManager->namespaces);

+ 1 - 0
src/server/ua_nodestore_interface.c

@@ -75,6 +75,7 @@ UA_NodeStoreInterface* UA_NodeStoreInterface_new(){
 UA_StatusCode UA_NodeStoreInterface_copy(const UA_NodeStoreInterface *src,UA_NodeStoreInterface *dst){
 	if(src!=UA_NULL){
 		if(dst!=UA_NULL){
+			//just copy the function pointers
 			dst->addNodes = src->addNodes;
 			dst->addReferences = src->addReferences;
 			dst->browseNodes = src->browseNodes;

+ 86 - 73
src/server/ua_server.c

@@ -40,12 +40,17 @@ void addSingleNode(UA_Namespace *namespace, UA_AddNodesItem *addNodesItem) {
 	namespace->nodeStore->addNodes(&tmpRequestHeader, addNodesItem, &indices,
 			indicesSize, &result, &diagnosticInfo);
 }
-static void UA_Server_registerNS0Operations(UA_Server *server, UA_NodeStoreInterface *nodestore){
-
-	UA_NodeStoreInterface_registerReadNodesOperation(nodestore,open62541NodeStore_ReadNodes);
-	UA_NodeStoreInterface_registerBrowseNodesOperation(nodestore,open62541NodeStore_BrowseNodes);
-	UA_NodeStoreInterface_registerAddNodesOperation(nodestore,open62541NodeStore_AddNodes);
-	UA_NodeStoreInterface_registerWriteNodesOperation(nodestore,open62541NodeStore_WriteNodes);
+static void UA_Server_registerNS0Operations(UA_Server *server,
+		UA_NodeStoreInterface *nodestore) {
+
+	UA_NodeStoreInterface_registerReadNodesOperation(nodestore,
+			open62541NodeStore_ReadNodes);
+	UA_NodeStoreInterface_registerBrowseNodesOperation(nodestore,
+			open62541NodeStore_BrowseNodes);
+	UA_NodeStoreInterface_registerAddNodesOperation(nodestore,
+			open62541NodeStore_AddNodes);
+	UA_NodeStoreInterface_registerWriteNodesOperation(nodestore,
+			open62541NodeStore_WriteNodes);
 }
 
 static void ns0_addObjectNode(UA_Server *server, UA_NodeId REFTYPE_NODEID,
@@ -82,12 +87,11 @@ static void ns0_addObjectNode(UA_Server *server, UA_NodeId REFTYPE_NODEID,
 	addSingleNode(ns0, &addNodesItem);
 	UA_ObjectAttributes_deleteMembers(&objAttr);
 	UA_AddNodesItem_deleteMembers(&addNodesItem);
-	UA_ByteString_deleteMembers(&addNodesItem.nodeAttributes.body);
 }
 static void ns0_addVariableNode(UA_Server *server, UA_NodeId refTypeNodeId,
 		UA_ExpandedNodeId requestedNodeId, UA_ExpandedNodeId parentNodeId,
-		UA_QualifiedName browseName, UA_LocalizedText displayName,
-		UA_LocalizedText description, UA_DataValue *dataValue,
+		UA_QualifiedName *browseName, UA_LocalizedText *displayName,
+		UA_LocalizedText *description, UA_DataValue *dataValue,
 		UA_Int32 valueRank) {
 	UA_VariableAttributes varAttr;
 	UA_VariableAttributes_init(&varAttr);
@@ -99,23 +103,27 @@ static void ns0_addVariableNode(UA_Server *server, UA_NodeId refTypeNodeId,
 	addNodesItem.requestedNewNodeId = requestedNodeId;
 	addNodesItem.referenceTypeId = refTypeNodeId;
 	addNodesItem.nodeClass = UA_NODECLASS_VARIABLE;
-	addNodesItem.browseName = browseName;
+	UA_QualifiedName_copy(browseName, &addNodesItem.browseName);
 	addNodesItem.typeDefinition.nodeId.identifier.numeric = 357;
 	addNodesItem.typeDefinition.nodeId.identifierType = UA_NODEIDTYPE_NUMERIC;
 	addNodesItem.typeDefinition.nodeId.namespaceIndex = 0;
 	addNodesItem.nodeAttributes.typeId = addNodesItem.typeDefinition.nodeId;
-	varAttr.displayName = displayName;
-	varAttr.description = description;
-	UA_Variant_copy(&dataValue->value,&varAttr.value);
+	UA_LocalizedText_copy(displayName, &varAttr.displayName);
+	UA_LocalizedText_copy(description, &varAttr.description);
+
+	//UA_Variant_copy(&dataValue->value,&varAttr.value);
 	varAttr.userWriteMask = 0;
 	varAttr.writeMask = 0;
+	UA_Variant_copy(&dataValue->value, &varAttr.value);
 
-	varAttr.dataType = dataValue->value.vt->typeId;
+	varAttr.dataType = varAttr.value.vt->typeId;
 	varAttr.valueRank = valueRank;
 	varAttr.specifiedAttributes |= UA_NODEATTRIBUTESMASK_VALUERANK;
 
-	varAttr.arrayDimensions =
-			(UA_UInt32*) dataValue->value.storage.data.arrayDimensions;
+	UA_Array_copy(dataValue->value.storage.data.arrayDimensions,
+			dataValue->value.storage.data.arrayDimensionsLength,
+			&UA_TYPES[UA_UINT32], (void**)&varAttr.arrayDimensions);
+
 	varAttr.arrayDimensionsSize =
 			dataValue->value.storage.data.arrayDimensionsLength;
 
@@ -134,14 +142,13 @@ static void ns0_addVariableNode(UA_Server *server, UA_NodeId refTypeNodeId,
 	addSingleNode(ns0, &addNodesItem);
 	UA_VariableAttributes_deleteMembers(&varAttr);
 	UA_AddNodesItem_deleteMembers(&addNodesItem);
-	UA_ByteString_deleteMembers(&addNodesItem.nodeAttributes.body);
 }
 
-static void ns0_addReferenceTypeNode(UA_Server *server, UA_NodeId REFTYPE_NODEID,
-		UA_ExpandedNodeId REQ_NODEID, UA_ExpandedNodeId PARENTNODEID,
-		char* REFTYPE_BROWSENAME, char* REFTYPE_DISPLAYNAME,
-		char*REFTYPE_DESCRIPTION, UA_Boolean IS_ABSTRACT,
-		UA_Boolean IS_SYMMETRIC) {
+static void ns0_addReferenceTypeNode(UA_Server *server,
+		UA_NodeId REFTYPE_NODEID, UA_ExpandedNodeId REQ_NODEID,
+		UA_ExpandedNodeId PARENTNODEID, char* REFTYPE_BROWSENAME,
+		char* REFTYPE_DISPLAYNAME, char*REFTYPE_DESCRIPTION,
+		UA_Boolean IS_ABSTRACT, UA_Boolean IS_SYMMETRIC) {
 	UA_AddNodesItem addNodesItem;
 	UA_AddNodesItem_init(&addNodesItem);
 	UA_Namespace *ns0;
@@ -159,7 +166,7 @@ static void ns0_addReferenceTypeNode(UA_Server *server, UA_NodeId REFTYPE_NODEID
 	refTypeAttr.symmetric = IS_SYMMETRIC;
 	refTypeAttr.userWriteMask = 0;
 	refTypeAttr.writeMask = 0;
-	UA_LocalizedText_copycstring(REFTYPE_DISPLAYNAME,&refTypeAttr.inverseName);
+	UA_LocalizedText_copycstring(REFTYPE_DISPLAYNAME, &refTypeAttr.inverseName);
 	refTypeAttr.specifiedAttributes |= UA_NODEATTRIBUTESMASK_BROWSENAME;
 	refTypeAttr.specifiedAttributes |= UA_NODEATTRIBUTESMASK_DISPLAYNAME;
 	refTypeAttr.specifiedAttributes |= UA_NODEATTRIBUTESMASK_DESCRIPTION;
@@ -174,7 +181,6 @@ static void ns0_addReferenceTypeNode(UA_Server *server, UA_NodeId REFTYPE_NODEID
 	addSingleNode(ns0, &addNodesItem);
 	UA_ReferenceTypeAttributes_deleteMembers(&refTypeAttr);
 	UA_AddNodesItem_deleteMembers(&addNodesItem);
-	UA_ByteString_deleteMembers(&addNodesItem.nodeAttributes.body);
 }
 
 UA_Server * UA_Server_new(UA_String *endpointUrl,
@@ -189,11 +195,12 @@ UA_Server * UA_Server_new(UA_String *endpointUrl,
 	//add namespace zero
 	UA_NodeStoreInterface nodestoreInterface;
 	UA_NamespaceManager_init(&server->namespaceManager);
-	if(!useOpen62541NodeStore){
+	if (!useOpen62541NodeStore) {
 		nodestoreInterface = *ns0Nodestore;
 	}
-	UA_Server_registerNS0Operations(server,&nodestoreInterface);
-	UA_NamespaceManager_createNamespace(&server->namespaceManager, 0, &nodestoreInterface);
+	UA_Server_registerNS0Operations(server, &nodestoreInterface);
+	UA_NamespaceManager_createNamespace(&server->namespaceManager, 0,
+			&nodestoreInterface);
 
 	// mockup application description
 	UA_ApplicationDescription_init(&server->description);
@@ -246,7 +253,7 @@ UA_Server * UA_Server_new(UA_String *endpointUrl,
 #define SESSIONLIFETIME 10000
 #define STARTSESSIONID 1
 	UA_SessionManager_init(&server->sessionManager, MAXSESSIONCOUNT,
-			SESSIONLIFETIME, STARTSESSIONID);
+	SESSIONLIFETIME, STARTSESSIONID);
 
 	//ns0: C2UA_STRING("http://opcfoundation.org/UA/"));
 	//ns1: C2UA_STRING("http://localhost:16664/open62541/"));
@@ -359,12 +366,10 @@ UA_Server * UA_Server_new(UA_String *endpointUrl,
 	UA_String_copycstring("http://opcfoundation.org/UA/",
 			&((UA_String *) (serverArrayValue.value.storage.data.dataPtr))[0]);
 	UA_String_copycstring("http://namespace123",
-				&((UA_String *) (serverArrayValue.value.storage.data.dataPtr))[1]);
-
-	UA_Int32 *arrayDim;
-	UA_UInt32 arrayDimSize = 1;
-	UA_Array_new((void**) &arrayDim, arrayDimSize, &UA_TYPES[UA_INT32]);
+			&((UA_String *) (serverArrayValue.value.storage.data.dataPtr))[1]);
 
+	UA_Int32 *arrayDim = UA_NULL;
+	UA_UInt32 arrayDimSize = -1;
 	serverArrayValue.value.vt = &UA_TYPES[UA_STRING];
 	serverArrayValue.value.storage.data.arrayDimensions = arrayDim;
 	serverArrayValue.value.storage.data.arrayDimensionsLength = arrayDimSize; // added to ensure encoding in readreponse
@@ -377,41 +382,43 @@ UA_Server * UA_Server_new(UA_String *endpointUrl,
 
 		UA_LocalizedText displayName;
 
-
 		UA_QualifiedName_copycstring("NamespaceArray", &browseName);
 		UA_LocalizedText_copycstring("NamespaceArray", &description);
 		UA_LocalizedText_copycstring("NamespaceArray", &displayName);
 
 		ns0_addVariableNode(server, RefTypeId_HasComponent.nodeId,
-				VarId_NamespaceArray, ObjId_Server, browseName, description,
-				displayName, &serverArrayValue, 1);
+				VarId_NamespaceArray, ObjId_Server, &browseName, &description,
+				&displayName, &serverArrayValue, 1);
+		UA_QualifiedName_deleteMembers(&browseName);
+		UA_LocalizedText_deleteMembers(&description);
+		UA_LocalizedText_deleteMembers(&displayName);
 
 	}
-
-
+	UA_DataValue_deleteMembers(&serverArrayValue);
 
 	// ServerStatus
 	UA_DataValue serverStatusValue;
 	UA_DataValue_init(&serverStatusValue);
 
-	UA_ServerStatusDataType *status = UA_ServerStatusDataType_new();
-
-	status->startTime = UA_DateTime_now();
-	status->currentTime = UA_DateTime_now();
-	status->state = UA_SERVERSTATE_RUNNING;
-	UA_String_copycstring("open62541.org", &status->buildInfo.productUri);
-	UA_String_copycstring("open62541", &status->buildInfo.manufacturerName);
-	UA_String_copycstring("open62541", &status->buildInfo.productName);
-	UA_String_copycstring("0.0", &status->buildInfo.softwareVersion);
-	UA_String_copycstring("0.0", &status->buildInfo.buildNumber);
-	status->buildInfo.buildDate = UA_DateTime_now();
-	UA_String_copycstring("en",&status->shutdownReason.locale);
-	UA_String_copycstring("because",&status->shutdownReason.text);
-	status->secondsTillShutdown = 99999999;
+	UA_ServerStatusDataType status;
+	UA_ServerStatusDataType_init(&status);
+
+	status.startTime = UA_DateTime_now();
+	status.currentTime = UA_DateTime_now();
+	status.state = UA_SERVERSTATE_RUNNING;
+	UA_String_copycstring("open62541.org", &status.buildInfo.productUri);
+	UA_String_copycstring("open62541", &status.buildInfo.manufacturerName);
+	UA_String_copycstring("open62541", &status.buildInfo.productName);
+	UA_String_copycstring("0.0", &status.buildInfo.softwareVersion);
+	UA_String_copycstring("0.0", &status.buildInfo.buildNumber);
+	status.buildInfo.buildDate = UA_DateTime_now();
+	UA_String_copycstring("en", &status.shutdownReason.locale);
+	UA_String_copycstring("because", &status.shutdownReason.text);
+	status.secondsTillShutdown = 99999999;
 
 	serverStatusValue.value.vt = &UA_TYPES[UA_SERVERSTATUSDATATYPE]; // gets encoded as an extensionobject
 	serverStatusValue.value.storage.data.arrayLength = 0;
-	serverStatusValue.value.storage.data.dataPtr = status;
+	serverStatusValue.value.storage.data.dataPtr = &status;
 	serverStatusValue.value.storage.data.arrayDimensionsLength = 0;
 	{
 		UA_QualifiedName browseName;
@@ -423,23 +430,27 @@ UA_Server * UA_Server_new(UA_String *endpointUrl,
 		UA_LocalizedText_copycstring("ServerStatus", &displayName);
 
 		ns0_addVariableNode(server, RefTypeId_HasComponent.nodeId,
-				VarId_ServerStatus, ObjId_Server, browseName, description,
-				displayName, &serverStatusValue, -1);
+				VarId_ServerStatus, ObjId_Server, &browseName, &description,
+				&displayName, &serverStatusValue, -1);
 
-	}
+		UA_QualifiedName_deleteMembers(&browseName);
+		UA_LocalizedText_deleteMembers(&description);
+		UA_LocalizedText_deleteMembers(&displayName);
 
+	}
+	UA_ServerStatusDataType_deleteMembers(&status);
 	// State (Component of ServerStatus)
 
 	UA_DataValue stateValue;
-
+	UA_DataValue_init(&stateValue);
 	stateValue.value.vt = &UA_TYPES[UA_SERVERSTATE];
 	stateValue.value.storage.data.arrayDimensionsLength = 0; // added to ensure encoding in readreponse
 	stateValue.value.storage.data.arrayLength = 0;
-	stateValue.value.storage.data.dataPtr = &status->state; // points into the other object.
+	stateValue.value.storage.data.dataPtr = &status.state; // points into the other object.
 	stateValue.value.storageType = UA_VARIANT_DATA;
 
 	{
-		UA_QualifiedName browseName ;
+		UA_QualifiedName browseName;
 		UA_LocalizedText description;
 		UA_LocalizedText displayName;
 
@@ -448,12 +459,13 @@ UA_Server * UA_Server_new(UA_String *endpointUrl,
 		UA_LocalizedText_copycstring("State", &displayName);
 
 		ns0_addVariableNode(server, RefTypeId_HasComponent.nodeId, VarId_State,
-				ObjId_Server, browseName, description, displayName,
+				ObjId_Server, &browseName, &description, &displayName,
 				&stateValue, -1);
-
+		UA_QualifiedName_deleteMembers(&browseName);
+		UA_LocalizedText_deleteMembers(&description);
+		UA_LocalizedText_deleteMembers(&displayName);
 	}
 
-
 	ns0_addObjectNode(server, RefTypeId_Organizes.nodeId, ObjId_TypesFolder,
 			ObjId_Root, "Types", "Types", "Types");
 
@@ -557,8 +569,8 @@ UA_Server * UA_Server_new(UA_String *endpointUrl,
 void UA_Server_addScalarVariableNode(UA_Server *server,
 		UA_QualifiedName *browseName, void *value, const UA_VTable_Entry *vt,
 		UA_ExpandedNodeId *parentNodeId, UA_NodeId *referenceTypeId) {
-	UA_DataValue *dataValue = UA_DataValue_new();
-
+	UA_DataValue dataValue;
+	UA_DataValue_init(&dataValue);
 	/*UA_LocalizedText_copycstring("integer value", &tmpNode->description); */
 	UA_LocalizedText displayName;
 	UA_LocalizedText description;
@@ -566,14 +578,13 @@ void UA_Server_addScalarVariableNode(UA_Server *server,
 	UA_LocalizedText_init(&displayName);
 	UA_LocalizedText_init(&description);
 
-
 	UA_String_copy(&browseName->name, &displayName.text);
 	UA_String_copy(&browseName->name, &description.text);
 
-	dataValue->value.vt = vt;
-	dataValue->value.storage.data.dataPtr = value;
-	dataValue->value.storageType = UA_VARIANT_DATA;
-	dataValue->value.storage.data.arrayLength = 1;
+	dataValue.value.vt = vt;
+	dataValue.value.storage.data.dataPtr = value;
+	dataValue.value.storageType = UA_VARIANT_DATA_NODELETE;
+	dataValue.value.storage.data.arrayLength = 1;
 	UA_ExpandedNodeId reqNodeId;
 	UA_ExpandedNodeId_init(&reqNodeId);
 	reqNodeId.namespaceUri.length = -1;
@@ -581,15 +592,17 @@ void UA_Server_addScalarVariableNode(UA_Server *server,
 	reqNodeId.nodeId.identifier.numeric = 222;
 	reqNodeId.nodeId.identifierType = UA_NODEIDTYPE_NUMERIC;
 	ns0_addVariableNode(server, *referenceTypeId, reqNodeId, *parentNodeId,
-			*browseName, displayName, description, dataValue, -1);
+			browseName, &displayName, &description, &dataValue, -1);
+	UA_DataValue_deleteMembers(&dataValue);
+	UA_LocalizedText_deleteMembers(&displayName);
+	UA_LocalizedText_deleteMembers(&description);
 
 }
 
 UA_Int32 UA_Server_addNamespace(UA_Server *server, UA_UInt16 namespaceIndex,
 		UA_NodeStoreInterface *nodeStore) {
 
-	return (UA_Int32) UA_NamespaceManager_createNamespace(&server->namespaceManager,
-			namespaceIndex, nodeStore);
+	return (UA_Int32) UA_NamespaceManager_createNamespace(
+			&server->namespaceManager, namespaceIndex, nodeStore);
 }
 
-