Hi.
I'm using cppcheck-2.7 and i noticed that there is a false alarm on double free, i get the following error message: /home/db/example.c:31:2: error: Memory pointed to by 'ptr' is freed twice. [doubleFree] On the following piece of code:
#include <stdlib.h> struct buf_t { void *ptr; }; int alloc_buf(struct buf_t *buf) { buf->ptr = malloc(10); if (buf->ptr == NULL) return 1; return 0; } int main() { struct buf_t buf; if (alloc_buf(&buf)) exit(1); free(buf.ptr); if (alloc_buf(&buf)) exit(1); free(buf.ptr); return 0; }
Maybe it is worth mentioning that for the following piece code there isn't any warning at all (i.e. using the struct causes this false alarm):
#include <stdlib.h> int alloc_buf(void **buf) { *buf = malloc(10); if (*buf == NULL) return 1; return 0; } int main() { void *buf; if (alloc_buf(&buf)) exit(1); free(buf); if (alloc_buf(&buf)) exit(1); free(buf); return 0; }
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11008
Log in to post a comment.
Hi.
I'm using cppcheck-2.7 and i noticed that there is a false alarm on double free,
i get the following error message:
/home/db/example.c:31:2: error: Memory pointed to by 'ptr' is freed twice. [doubleFree]
On the following piece of code:
Maybe it is worth mentioning that for the following piece code there isn't any warning at all (i.e. using the struct causes this false alarm):
Last edit: Dotan Barak 2022-04-24
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11008