Skip to content

Fix disposing SessionIdLoggingContext if CheckAndUpdateSessionStatus is failed #1462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/NHibernate/Impl/AbstractSessionImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,26 @@ public ProcessHelper(AbstractSessionImpl session)
{
_session = session;
_context = new SessionIdLoggingContext(session.SessionId);
session.CheckAndUpdateSessionStatus();
_session._processing = true;
try
{
_session.CheckAndUpdateSessionStatus();
_session._processing = true;
}
catch
{
_context.Dispose();
_context = null;
throw;
}
}

public void Dispose()
{
_context.Dispose();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If disposed is called multiple times, this will cause a null ref. We need a ?. here.

_context = null;
if (_session == null)
throw new ObjectDisposedException("The session process helper has been disposed already");
_session._processing = false;
_context.Dispose();
_context = null;
_session = null;
}
}
Expand Down