/*++

    Copyright (c) Microsoft Corporation.  All rights reserved.

Rule Name:

    DanglingDeviceObjectReference

Domain:

    wdm

Rule ID:

    Not Applicable

Description:

    This rule verifies that a driver calls ObDereferenceObject
    with a pointer from a previous call to
    IoGetAttachedDeviceReference.

Help Link:

    https://go.microsoft.com/fwlink/?LinkId=507476

--*/


#include "slic_base.h"

state 
{
    int ReferenceCount = 0;
} 

IoGetAttachedDeviceReference.exit
{
    if($return==NULL)
    {
        halt;
    }
    else
    {
        ReferenceCount = ReferenceCount + 1;
    }
}

[ObDereferenceObject,ObfDereferenceObject].entry 
{
        ReferenceCount = ReferenceCount - 1;
}

sdv_main.exit
{
    if ( ReferenceCount > 0 ) 
    {
        abort "The driver has not called ObDereferenceObject after calling IoGetAttachedDeviceReference.";
    }
}
