Permalink
Browse files

Fixed a memory leak when marshalling std::string in C#.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information...
ddobrev committed Jul 12, 2017
1 parent d996053 commit a7cf9844861d616ed4ee5c41905a9c235ee20584

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -96,21 +96,20 @@ public override void CSharpMarshalToManaged(CSharpMarshalContext ctx)
ClassTemplateSpecialization basicString = GetBasicString(type);
var c_str = basicString.Properties.First(p => p.OriginalName == "c_str");
var typePrinter = new CSharpTypePrinter(ctx.Context);
if (type.IsAddress() || ctx.Declaration is Field)
const string varBasicString = "__basicStringRet";
ctx.Before.WriteLine("var {0} = {1}.{2}({3});",
varBasicString, basicString.Visit(typePrinter),
Helpers.CreateInstanceIdentifier, ctx.ReturnVarName);
if (type.IsAddress())
{
ctx.Return.Write("{0}.{1}({2}).{3}",
basicString.Visit(typePrinter), Helpers.CreateInstanceIdentifier,
ctx.ReturnVarName, c_str.Name);
ctx.Return.Write($"{varBasicString}.{c_str.Name}");
}
else
{
const string varBasicString = "__basicStringRet";
ctx.Before.WriteLine("using (var {0} = {1}.{2}({3}))",
varBasicString, basicString.Visit(typePrinter),
Helpers.CreateInstanceIdentifier, ctx.ReturnVarName);
ctx.Before.WriteStartBraceIndent();
ctx.Return.Write($"{varBasicString}.{c_str.Name}");
ctx.HasCodeBlock = true;
const string varString = "__stringRet";
ctx.Before.WriteLine($"var {varString} = {varBasicString}.{c_str.Name};");
ctx.Before.WriteLine($"{varBasicString}.Dispose(false);");
ctx.Return.Write(varString);
}
}

0 comments on commit a7cf984

Please sign in to comment.