Skip to content

Commit

Permalink
Fixed ballots to free the memory even tho it thinks it is already clo…
Browse files Browse the repository at this point in the history
…sed. (#328)
  • Loading branch information
SteveMaier-IRT authored Sep 15, 2022
1 parent b418953 commit 9d559b4
Show file tree
Hide file tree
Showing 5 changed files with 967 additions and 7 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<!-- Project -->
<RootNamespace>ElectionGuard</RootNamespace>
<AssemblyName>ElectionGuard.Encryption</AssemblyName>
<Version>0.1.16</Version>
<AssemblyVersion>0.1.16.0</AssemblyVersion>
<AssemblyFileVersion>0.1.16.0</AssemblyFileVersion>
<Version>0.1.17</Version>
<AssemblyVersion>0.1.17.0</AssemblyVersion>
<AssemblyFileVersion>0.1.17.0</AssemblyFileVersion>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -19,7 +19,7 @@
<Title>ElectionGuard Encryption</Title>
<Description>Open source implementation of ElectionGuard's ballot encryption.</Description>
<Authors>Microsoft</Authors>
<PackageVersion>0.1.16</PackageVersion>
<PackageVersion>0.1.17</PackageVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/microsoft/electionguard-cpp</PackageProjectUrl>
<RepositoryUrl>https://github.com/microsoft/electionguard-cpp</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ internal unsafe ElectionguardSafeHandle(

public IntPtr Ptr => handle;

protected bool IsFreed = false;

protected abstract bool Free();

protected override bool ReleaseHandle()
Expand All @@ -59,6 +61,7 @@ protected override bool ReleaseHandle()
var freed = Free();
if (freed)
{
IsFreed = true;
Close();
}
return freed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2793,7 +2793,7 @@ internal class PlaintextBallotHandle
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
protected override bool Free()
{
if (IsClosed) return true;
if (IsFreed) return true;

var status = PlaintextBallot.Free(TypedPtr);
if (status != Status.ELECTIONGUARD_STATUS_SUCCESS)
Expand Down Expand Up @@ -2924,7 +2924,7 @@ internal class CiphertextBallotHandle
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
protected override bool Free()
{
if (IsClosed) return true;
if (IsFreed) return true;

var status = CiphertextBallot.Free(TypedPtr);
if (status != Status.ELECTIONGUARD_STATUS_SUCCESS)
Expand Down Expand Up @@ -3118,7 +3118,7 @@ internal class SubmittedBallotHandle
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
protected override bool Free()
{
if (IsClosed) return true;
if (IsFreed) return true;

var status = SubmittedBallot.Free(TypedPtr);
if (status != Status.ELECTIONGUARD_STATUS_SUCCESS)
Expand Down
Loading

0 comments on commit 9d559b4

Please sign in to comment.