tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
re: valgrind
On Mon, 21 Mar 2022, matthew green wrote:
try clang, which usually has newer/better sanitizers.
Sanitizers are OK, but, they don't seem to work in some cases:
Case 1: Global allocation
---
$ cat global_alloc.c
#include <stdlib.h>
#include <string.h>
void* p;
int
main(void)
{
p = malloc(1000);
memset(p, '\0', 1000);
return 0;
}
$ clang --version
clang version 13.0.1
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/llvm/bin
$ clang -Wall -g -fsanitize=address -o 1 global_alloc.c
$ env ASAN_OPTIONS=detect_leaks=1 ./1
$
---
Case 2: Static allocation
---
$ cat static_alloc.c
#include <stdlib.h>
#include <string.h>
static char*
mkbuf(size_t len)
{
static void* sbuf = NULL;
static size_t slen = 0;
if (len > slen) {
sbuf = realloc(sbuf, len);
slen = len;
}
return sbuf;
}
int
main(void)
{
char* p = mkbuf(1000);
memset(p, '\0', 1000);
return 0;
}
$ clang -Wall -g -fsanitize=address -o 2 static_alloc.c
$ env ASAN_OPTIONS=detect_leaks=1 ./2
$
---
Valgrind, of course, detects both those leaks.
-RVP
PS. Mouse's email server will, as usual, reject mails sent from SDF I
think... ;)
Home |
Main Index |
Thread Index |
Old Index