Skip to content

Commit

Permalink
Plug memory leak in StringMarshaller (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjk authored Jul 11, 2021
1 parent 5d998fd commit 36a22d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,7 @@ unsafe partial class C : global::Foo.IStr
Marshal.ThrowExceptionForHR(result);
}
Marshal.FreeCoTaskMem(local_1);
}
finally
{
Expand Down
5 changes: 5 additions & 0 deletions WinFormsComInterop.SourceGenerator/StringMarshaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public override void UnmarshalParameter(IndentedStringBuilder builder)
{
builder.AppendLine($"{Name} = Marshal.PtrToStringUni({LocalVariable});");
}

if (RefKind != RefKind.Out && Index != -1)
{
builder.AppendLine($"Marshal.FreeCoTaskMem({LocalVariable});");
}
}
}
}

0 comments on commit 36a22d2

Please sign in to comment.