Skip to content

Latest commit

 

History

History
49 lines (39 loc) · 1.06 KB

c26167.md

File metadata and controls

49 lines (39 loc) · 1.06 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: Warning C26167
Warning C26167
11/04/2016
C26167
C26167
5a3d767f-31fa-45e0-8c9b-1aa776acaa45

Warning C26167

Possibly releasing unheld lock 'lock' in function 'func'.

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

Examples

The following code will generate C26167 and C26110.

typedef struct _DATA {
    CRITICAL_SECTION cs;
} DATA;

_Releases_lock_(p->cs) void Leave(DATA* p) {
    LeaveCriticalSection(&p->cs); // OK
}
void ReleaseUnheldLock(DATA* p) { // Warning C26167
    int i = 0;
    Leave(p); // Warning C26110
}

The following code will correct these warnings.

typedef struct _DATA {
    CRITICAL_SECTION cs;
} DATA;

_Releases_lock_(p->cs) void Leave(DATA* p) {
    LeaveCriticalSection( &p->cs );
}

void ReleaseUnheldLock( DATA* p ) {
    EnterCriticalSection( &p->cs );
    int i = 0;
    Leave(p);
}