Skip to content

Null checks in incorrect order in Cordb::Terminate #47463

Closed

Description

@omajid

There's a null-check for m_rcEventThread in Cordb::Terminate here:

if (m_rcEventThread != NULL)

But the variable is already used without null-testing a littler earlier in the same method:

if (m_rcEventThread->IsRCEventThread())

If the variable was actually null, dereferencing it leads to undefined behaviour, so a compiler is free to assume that wont happen. A recent compiler might therefore remove the null check on line 1125 entirely. We should probably null-check m_rcEventThread everywhere, or remove the null-checks.

Activity

  1. ghost added
    area-CodeGen-coreclr
    on Jan 26, 2021
  2. ghost added
    untriaged
    on Jan 26, 2021
  3. removed
    area-CodeGen-coreclr
    on Jan 26, 2021
  4. added
    help wanted
    and removed
    untriaged
    on Jan 26, 2021
  5. added this to the Future milestone on Jan 26, 2021
  6. tommcdon commented on Jan 26, 2021

    @tommcdon
    Member

    @omajid would you be interested in submitting a PR for this issue?

  7. omajid commented on Jan 26, 2021

    @omajid
    MemberAuthor

    Sure. I am not sure of the best fix: should I add additional guards for NULL?

  8. GilesDMiddleton commented on Apr 18, 2021

    @GilesDMiddleton
    Contributor

    Just been looking at this for fun. I'm a beginner in this repo, so apologies if I'm doing something wrong.

    I think the null check on line 1125 is superfluous because m_rcEventThread will always be null if m_initialized is false, and can be removed. and m_initialize is tested at the start of the function.
    Would it be bad/good to turn m_initialized into a function IsIntialized() which tested !m_rcEventThread, or just use m_rcEventThread and remove m_initialized completely? And shouldn't it be called m_pEventThread?

    other observations:
    m_initialized uses a mix of lower case bool on initialization and uppercase BOOL in other parts. should be FALSE in ctor.
    m_rcEventThread is not initialized to null in neither the ctor nor header. Is that for speed?
    If anyone can help me find an automated test that covers this area - please tell me, as I'm failing to find one.
    Other uses of m_rcEventThread are untested, and do not test m_initialized such as Cordb::RemoveProcess

  9. AaronRobinsonMSFT commented on Mar 10, 2022

    @AaronRobinsonMSFT
    Member

    I think the null check on line 1125 is superfluous because m_rcEventThread will always be null if m_initialized is false, and can be removed. and m_initialize is tested at the start of the function.

    @GilesDMiddleton Agreed. I think the if check can be safely removed.

    If anyone can help me find an automated test that covers this area - please tell me, as I'm failing to find one.

    This part of the product is tested in a private repo.

  10. dotnet-policy-service commented on Oct 19, 2026

    @dotnet-policy-service
    Contributor

    Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

    This process is part of our issue cleanup automation.

  11. dotnet-policy-service commented on Oct 19, 2026

    @dotnet-policy-service
    Contributor

    Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

    This process is part of our issue cleanup automation.

  12. added
    backlog-cleanup-candidate
    on Oct 19, 2026
  13. added
    in-pr
    on Oct 29, 2026
  14. added a commit that references this issue on Oct 31, 2026
    d02edc2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Diagnostics-coreclrbacklog-cleanup-candidatehelp wantedin-prno-recent-activity

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions