Skip to content

Commit

Permalink
Fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
chtenb committed Feb 16, 2024
1 parent 45f9e38 commit 7b5ca5b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Rubjerg.Graphviz.Test/TestDotLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public void TestLayoutMethodsWithoutLayout()
{
CreateSimpleTestGraph(out RootGraph root, out Node nodeA, out Edge edge);

Assert.AreEqual(root.GetBoundingBox(), default(RectangleD));
Assert.AreEqual(default(RectangleD), root.GetBoundingBox(), "Unexpected graph boundingbox");
Assert.AreEqual(root.GetDrawing().Count, 0);
Assert.AreEqual(root.GetLabelDrawing().Count, 0);

Assert.AreEqual(nodeA.GetPosition(), default(PointD));
Assert.AreEqual(nodeA.GetBoundingBox(), default(RectangleD));
Assert.AreEqual(nodeA.GetSize(), default(SizeD));
Assert.AreEqual(default(PointD), nodeA.GetPosition(), "Unexpected node position");
Assert.AreEqual(default(RectangleD), nodeA.GetBoundingBox(), "Unexpected node boundingbox");
Assert.AreEqual(default(SizeD), nodeA.GetSize(), "Unexpected node size");
Assert.AreEqual(nodeA.GetRecordRectangles().Count(), 0);
Assert.AreEqual(nodeA.GetDrawing().Count, 0);
Assert.AreEqual(nodeA.GetLabelDrawing().Count, 0);
Expand Down
12 changes: 11 additions & 1 deletion Rubjerg.Graphviz/XDotParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,17 @@ internal static class XDotParser
public static List<XDotOp> ParseXDot(string xdotString, CoordinateSystem coordinateSystem, double maxY)
{
IntPtr xdot = XDotFFI.ParseXDot(xdotString);
return TranslateXDot(xdot, coordinateSystem, maxY);
try
{
return TranslateXDot(xdot, coordinateSystem, maxY);
}
finally
{
if (xdot != IntPtr.Zero)
{
XDotFFI.freeXDot(xdot);
}
}
}

internal static List<XDotOp> TranslateXDot(IntPtr xdotPtr, CoordinateSystem coordinateSystem, double maxY)
Expand Down

0 comments on commit 7b5ca5b

Please sign in to comment.