sqc 0.4.13

Software Code Quality - CERT C compliance checker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
 * Rule: CON06-C
 * Source: wiki
 * Status: FAIL - Local mutex destroyed before heap data freed
 */

#include <stdlib.h>
#include <threads.h>

void bad_func(void) {
    mtx_t local_mutex;
    mtx_init(&local_mutex, mtx_plain);
    char *shared_data = malloc(100);
    /* ... use shared_data under mutex ... */
    mtx_destroy(&local_mutex);
    /* shared_data still allocated — mutex doesn't outlive data */
    free(shared_data);
}