Georgiy Komarov - 2020-06-05

Hello,

I'm trying to use inline suppression for memory leak in the following C
code:

#include <pthread.h>
#include <stdlib.h>

static void *th(void *param)
{
    free(param);
}

int main(void)
{
    pthread_t tid;
    char *arg = malloc(42);

    if ((pthread_create(&tid, NULL, (void *)(th), (void *)arg)) != 0) {
        free(arg);
        return -1;
    }

    // cppcheck-suppress memleak
    return 0; // cppcheck-suppress memleak
    // cppcheck-suppress memleak
}

I'm calling Cppcheck by this way: cppcheck --language=c -q --library=posix.cfg --library=std.cfg source.c, and I get the following
output:

source.c:19:5: error: Memory leak: arg [memleak]
    return 0; // cppcheck-suppress memleak

This is the latest Cppcheck and configuration files from git master
(commit 5477c54).

How to set inline suppression for this memory leak? What am I doing wrong?

Thanks!


Update: I figured it out, just forgot --inline-suppr. Sorry for this noise.

--
Best regards,
Georgy Komarov

 

Last edit: Georgiy Komarov 2020-06-05