Skip to content

Commit

Permalink
Addition to fix #31.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Sicard committed Nov 2, 2016
1 parent 66f1810 commit 9963732
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions source/d2sqlite3.d
Original file line number Diff line number Diff line change
Expand Up @@ -1371,8 +1371,22 @@ private:
~this()
{
auto result = sqlite3_finalize(handle);
enforce(result == SQLITE_OK, new SqliteException(errmsg(handle), result));
handle = null;

// Check that destructor was not call by the GC
// See https://p0nce.github.io/d-idioms/#GC-proof-resource-class
try
{
enforce(result == SQLITE_OK, new SqliteException(errmsg(handle), result));
}
catch (InvalidMemoryOperationError e)
{
import core.stdc.stdio;
fprintf(stderr, "Error: release of Statement resource incorrectly"
~ " depends on destructors called by the GC.\n");
assert(false); // crash
}

handle = null;
}

@disable this(this);
Expand Down

0 comments on commit 9963732

Please sign in to comment.