Skip to content

Commit 9d559b4

Browse files
Fixed ballots to free the memory even tho it thinks it is already closed. (#328)
1 parent b418953 commit 9d559b4

File tree

5 files changed

+967
-7
lines changed

5 files changed

+967
-7
lines changed

bindings/netstandard/ElectionGuard/ElectionGuard.Encryption.Tests/TestEncrypt.cs

Lines changed: 40 additions & 0 deletions
Large diffs are not rendered by default.

bindings/netstandard/ElectionGuard/ElectionGuard.Encryption/ElectionGuard.Encryption.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<!-- Project -->
88
<RootNamespace>ElectionGuard</RootNamespace>
99
<AssemblyName>ElectionGuard.Encryption</AssemblyName>
10-
<Version>0.1.16</Version>
11-
<AssemblyVersion>0.1.16.0</AssemblyVersion>
12-
<AssemblyFileVersion>0.1.16.0</AssemblyFileVersion>
10+
<Version>0.1.17</Version>
11+
<AssemblyVersion>0.1.17.0</AssemblyVersion>
12+
<AssemblyFileVersion>0.1.17.0</AssemblyFileVersion>
1313
</PropertyGroup>
1414

1515
<PropertyGroup>
@@ -19,7 +19,7 @@
1919
<Title>ElectionGuard Encryption</Title>
2020
<Description>Open source implementation of ElectionGuard's ballot encryption.</Description>
2121
<Authors>Microsoft</Authors>
22-
<PackageVersion>0.1.16</PackageVersion>
22+
<PackageVersion>0.1.17</PackageVersion>
2323
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2424
<PackageProjectUrl>https://github.com/microsoft/electionguard-cpp</PackageProjectUrl>
2525
<RepositoryUrl>https://github.com/microsoft/electionguard-cpp</RepositoryUrl>

bindings/netstandard/ElectionGuard/ElectionGuard.Encryption/ElectionguardSafeHandle.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ internal unsafe ElectionguardSafeHandle(
5050

5151
public IntPtr Ptr => handle;
5252

53+
protected bool IsFreed = false;
54+
5355
protected abstract bool Free();
5456

5557
protected override bool ReleaseHandle()
@@ -59,6 +61,7 @@ protected override bool ReleaseHandle()
5961
var freed = Free();
6062
if (freed)
6163
{
64+
IsFreed = true;
6265
Close();
6366
}
6467
return freed;

bindings/netstandard/ElectionGuard/ElectionGuard.Encryption/NativeInterface.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2793,7 +2793,7 @@ internal class PlaintextBallotHandle
27932793
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
27942794
protected override bool Free()
27952795
{
2796-
if (IsClosed) return true;
2796+
if (IsFreed) return true;
27972797

27982798
var status = PlaintextBallot.Free(TypedPtr);
27992799
if (status != Status.ELECTIONGUARD_STATUS_SUCCESS)
@@ -2924,7 +2924,7 @@ internal class CiphertextBallotHandle
29242924
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
29252925
protected override bool Free()
29262926
{
2927-
if (IsClosed) return true;
2927+
if (IsFreed) return true;
29282928

29292929
var status = CiphertextBallot.Free(TypedPtr);
29302930
if (status != Status.ELECTIONGUARD_STATUS_SUCCESS)
@@ -3118,7 +3118,7 @@ internal class SubmittedBallotHandle
31183118
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
31193119
protected override bool Free()
31203120
{
3121-
if (IsClosed) return true;
3121+
if (IsFreed) return true;
31223122

31233123
var status = SubmittedBallot.Free(TypedPtr);
31243124
if (status != Status.ELECTIONGUARD_STATUS_SUCCESS)

0 commit comments

Comments
 (0)