Share via


Avviso C26167

È possibile rilasciare il blocco non bloccato 'lock' nella funzione 'func'.

L'avviso C26167 è simile all'avviso C26117 , ad eccezione del fatto che il livello di attendibilità è inferiore. Ad esempio, la funzione può contenere errori di annotazione.

Esempi

Il codice seguente genererà C26167 e 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
}

Il codice seguente correggerà questi avvisi.

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);
}