Skip to content

Commit 65aa0aa

Browse files
committed
Add Leaks build configuration for libgit2#141
1 parent 8220ec6 commit 65aa0aa

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
<WarningLevel>4</WarningLevel>
3333
<DocumentationFile />
3434
</PropertyGroup>
35+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Leaks|AnyCPU' ">
36+
<DebugSymbols>true</DebugSymbols>
37+
<DebugType>full</DebugType>
38+
<Optimize>false</Optimize>
39+
<OutputPath>bin\Leaks\</OutputPath>
40+
<DefineConstants>TRACE;DEBUG;NET35</DefineConstants>
41+
<ErrorReport>prompt</ErrorReport>
42+
<WarningLevel>4</WarningLevel>
43+
<DocumentationFile />
44+
</PropertyGroup>
3545
<ItemGroup>
3646
<Reference Include="System" />
3747
<Reference Include="System.Core" />

LibGit2Sharp.sln

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@ EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|Any CPU = Debug|Any CPU
11+
Leaks|Any CPU = Leaks|Any CPU
1112
Release|Any CPU = Release|Any CPU
1213
EndGlobalSection
1314
GlobalSection(ProjectConfigurationPlatforms) = postSolution
1415
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1516
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Any CPU.Build.0 = Debug|Any CPU
17+
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Leaks|Any CPU.ActiveCfg = Leaks|Any CPU
18+
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Leaks|Any CPU.Build.0 = Leaks|Any CPU
1619
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Release|Any CPU.ActiveCfg = Release|Any CPU
1720
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Release|Any CPU.Build.0 = Release|Any CPU
1821
{286E63EB-04DD-4ADE-88D6-041B57800761}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1922
{286E63EB-04DD-4ADE-88D6-041B57800761}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{286E63EB-04DD-4ADE-88D6-041B57800761}.Leaks|Any CPU.ActiveCfg = Leaks|Any CPU
24+
{286E63EB-04DD-4ADE-88D6-041B57800761}.Leaks|Any CPU.Build.0 = Leaks|Any CPU
2025
{286E63EB-04DD-4ADE-88D6-041B57800761}.Release|Any CPU.ActiveCfg = Release|Any CPU
2126
{286E63EB-04DD-4ADE-88D6-041B57800761}.Release|Any CPU.Build.0 = Release|Any CPU
2227
EndGlobalSection

LibGit2Sharp/Core/Handles/SafeHandleBase.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,36 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Runtime.InteropServices;
34

45
namespace LibGit2Sharp.Core.Handles
56
{
67
internal abstract class SafeHandleBase : SafeHandle
78
{
9+
#if LEAKS
10+
private readonly string trace;
11+
#endif
12+
813
protected SafeHandleBase()
914
: base(IntPtr.Zero, true)
1015
{
16+
#if LEAKS
17+
trace = new StackTrace(2, true).ToString();
18+
#endif
19+
}
20+
21+
protected override void Dispose(bool disposing)
22+
{
23+
#if DEBUG
24+
if (!disposing && !IsInvalid)
25+
{
26+
Trace.WriteLine(string.Format("A {0} handle wrapper has not been properly disposed.", GetType().Name));
27+
#if LEAKS
28+
Trace.WriteLine(trace);
29+
#endif
30+
Trace.WriteLine("");
31+
}
32+
#endif
33+
base.Dispose(disposing);
1134
}
1235

1336
public override bool IsInvalid

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@
3737
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
3838
<DocumentationFile>bin\Release\LibGit2Sharp.xml</DocumentationFile>
3939
</PropertyGroup>
40+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Leaks|AnyCPU'">
41+
<DebugSymbols>true</DebugSymbols>
42+
<DebugType>full</DebugType>
43+
<Optimize>false</Optimize>
44+
<OutputPath>bin\Leaks\</OutputPath>
45+
<DefineConstants>TRACE;DEBUG;NET35;LEAKS</DefineConstants>
46+
<ErrorReport>prompt</ErrorReport>
47+
<WarningLevel>4</WarningLevel>
48+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
49+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
50+
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
51+
</PropertyGroup>
4052
<ItemGroup>
4153
<Reference Include="System" />
4254
<Reference Include="System.Core" />

0 commit comments

Comments
 (0)