On Wed, Nov 23, 2016 at 2:26 PM, David C. Rankin <drankinatty@suddenlinkmail.com> wrote:
All,
valgrind is reporting an additional allocation and free along with and additional 1M of memory used. Below, 11 bytes should be allocated and freed. Instead valgrind reports 1035 bytes. (it's worse if you use strdup). For example:
#include <stdio.h> #include <stdlib.h> #include <string.h>
enum { MAXC = 16 };
int main (void) {
char buf[] = "0123456789"; size_t len = strlen (buf); char *s = NULL;
s = malloc (len + 1); snprintf (s, len + 1, "%s", buf);
printf (" s : %s\n", s);
free (s);
return 0; }
The report from valgrind:
valgrind ./bin/valgrindchk ==3917== Memcheck, a memory error detector ==3917== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al. ==3917== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info ==3917== Command: ./bin/valgrindchk ==3917== s : 0123456789 ==3917== ==3917== HEAP SUMMARY: ==3917== in use at exit: 0 bytes in 0 blocks ==3917== total heap usage: 2 allocs, 2 frees, 1,035 bytes allocated ==3917== ==3917== All heap blocks were freed -- no leaks are possible ==3917== ==3917== For counts of detected and suppressed errors, rerun with: -v ==3917== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Anybody else experience this problem? Anybody got a fix? I don't find anything valgrind related with a cursory search, did a patch get missed with the latest build?
-- David C. Rankin, J.D.,P.E.
In glibc, printf calls malloc. See http://stackoverflow.com/questions/6743034/does-fprintf-use-malloc-under-the...