Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Latest commit

 

History

History
75 lines (59 loc) · 1.73 KB

c26165.md

File metadata and controls

75 lines (59 loc) · 1.73 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: Warning C26165
Warning C26165
11/04/2016
C26165
C26165
a1d89bd6-08f3-4215-8a0c-b8ecfeb0cffc

Warning C26165

Possibly failing to release lock 'lock' in function 'func'.

Warning C26165 resembles warning C26115 except that the confidence level is lower. For example, the function may contain annotation errors.

Examples

The following code generates warning C26165.

_Create_lock_level_(LockLevelOne);
_Create_lock_level_(LockLevelTwo);

struct LockLevelledStruct
{
    _Has_lock_level_(LockLevelOne) CRITICAL_SECTION a;
    _Has_lock_level_(LockLevelTwo) CRITICAL_SECTION b;
};

_Lock_level_order_(LockLevelOne, LockLevelTwo);

_Acquires_lock_(s->b) void GetLockFunc(LockLevelledStruct* s)
{
    EnterCriticalSection(&s->b);
}

void testLockLevelledStruct(LockLevelledStruct* s) // Warning C26165
{
    EnterCriticalSection(&s->a);
    GetLockFunc(s);
    LeaveCriticalSection(&s->a);
}

To correct this warning, change the previous example to the following.

_Create_lock_level_(LockLevelOne);
_Create_lock_level_(LockLevelTwo);

struct LockLevelledStruct
{
    _Has_lock_level_(LockLevelOne) CRITICAL_SECTION a;
    _Has_lock_level_(LockLevelTwo) CRITICAL_SECTION b;
};

_Lock_level_order_(LockLevelOne, LockLevelTwo);

_Acquires_lock_(s->b) void GetLockFunc(LockLevelledStruct* s)
{
    EnterCriticalSection(&s->b);
}

_Releases_lock_(s->b) void ReleaseLockFunc(LockLevelledStruct* s)
{
    LeaveCriticalSection(&s->b);
}

void testLockLevelledStruct(LockLevelledStruct* s) // OK
{
    EnterCriticalSection(&s->a);
    GetLockFunc(s);
    ReleaseLockFunc(s);
    LeaveCriticalSection(&s->a);
}