Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
C26167
Collapse the table of content
Expand the table of content

C26167

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.

The following code will generate C26167, as well as 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);
} 
Show:
© 2015 Microsoft