- .NET API: Fixed memory release problem in method

ModelNode.GetObjectReference
pull/331/head
Michael Zillgith 4 years ago
parent 7185c3b8d4
commit da08489bc3

@ -1227,16 +1227,20 @@ namespace IEC61850
/// <param name="withoutIedName">If set to <c>true</c> the object reference is created without IED name.</param> /// <param name="withoutIedName">If set to <c>true</c> the object reference is created without IED name.</param>
public string GetObjectReference(bool withoutIedName = false) public string GetObjectReference(bool withoutIedName = false)
{ {
IntPtr objRefPtr = ModelNode_getObjectReferenceEx(self, IntPtr.Zero, withoutIedName); IntPtr nativeMemory = Marshal.AllocHGlobal(130);
IntPtr objRefPtr = ModelNode_getObjectReferenceEx(self, nativeMemory, withoutIedName);
if (objRefPtr != IntPtr.Zero) { if (objRefPtr != IntPtr.Zero) {
string objRef = Marshal.PtrToStringAnsi(objRefPtr); string objRef = Marshal.PtrToStringAnsi(objRefPtr);
Marshal.FreeHGlobal(objRefPtr); Marshal.FreeHGlobal(nativeMemory);
return objRef; return objRef;
} }
else { else {
Marshal.FreeHGlobal(nativeMemory);
return null; return null;
} }
} }

@ -49,11 +49,11 @@ namespace server_goose_publisher
{ {
if (cbEvent == 1) if (cbEvent == 1)
{ {
Console.WriteLine("GCB " + goCB.LN.GetName() + ":" + goCB.Name + " enabled"); Console.WriteLine("GCB " + goCB.LN.GetObjectReference() + ":" + goCB.Name + " enabled");
} }
else else
{ {
Console.WriteLine("GCB " + goCB.LN.GetName() + ":" + goCB.Name + " disabled"); Console.WriteLine("GCB " + goCB.LN.GetObjectReference() + ":" + goCB.Name + " disabled");
} }
}, null); }, null);

Loading…
Cancel
Save