Skip to content

Commit 3196707

Browse files
committed
Fix potential NullReferenceException in Dispose.
Fixes a crash if 'm_resultSet' isn't set yet (e.g., because ReadFirstResultSetAsync threw an exception and finally blocks are being run as the stack is unwound).
1 parent 188e616 commit 3196707

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/MySqlConnector/MySqlClient/MySqlDataReader.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,18 +269,21 @@ private void DoClose()
269269
{
270270
if (Command != null)
271271
{
272-
try
272+
if (m_resultSet != null)
273273
{
274-
while (NextResult())
274+
try
275275
{
276+
while (NextResult())
277+
{
278+
}
276279
}
277-
}
278-
catch (MySqlException ex) when (ex.Number == (int) MySqlErrorCode.QueryInterrupted)
279-
{
280-
// ignore "Query execution was interrupted" exceptions when closing a data reader
280+
catch (MySqlException ex) when (ex.Number == (int) MySqlErrorCode.QueryInterrupted)
281+
{
282+
// ignore "Query execution was interrupted" exceptions when closing a data reader
283+
}
284+
m_resultSet = null;
281285
}
282286

283-
m_resultSet = null;
284287
m_resultSetBuffered = null;
285288
m_nextResultSetBuffer.Clear();
286289

0 commit comments

Comments
 (0)