I use private anonymous mmap to allocate memory in my code, but when I use valgrind to check memory leak. I got following error. I don't think there is any memory error in the code.Thanks for help!
the command: valgrind --tool=memcheck ./a.out the error: ==2309== Memcheck, a memory error detector ==2309== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==2309== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info ==2309== Command: ./a.out ==2309== ==2309== Invalid write of size 1 ==2309== at 0x8048751: main (test.cpp:15) ==2309== Address 0xffffffff is not stack'd, malloc'd or (recently) free'd ==2309== ==2309== ==2309== Process terminating with default action of signal 11 (SIGSEGV) ==2309== Access not within mapped region at address 0xFFFFFFFF ==2309== at 0x8048751: main (test.cpp:15) ==2309== If you believe this happened as a result of a stack ==2309== overflow in your program's main thread (unlikely but ==2309== possible), you can try to increase the size of the ==2309== main thread stack using the --main-stacksize= flag. ==2309== The main thread stack size used in this run was 8388608. ==2309== ==2309== HEAP SUMMARY: ==2309== in use at exit: 1,264 bytes in 1 blocks ==2309== total heap usage: 2 allocs, 1 frees, 1,616 bytes allocated ==2309== ==2309== LEAK SUMMARY: ==2309== definitely lost: 0 bytes in 0 blocks ==2309== indirectly lost: 0 bytes in 0 blocks ==2309== possibly lost: 0 bytes in 0 blocks ==2309== still reachable: 1,264 bytes in 1 blocks ==2309== suppressed: 0 bytes in 0 blocks ==2309== Rerun with --leak-check=full to see details of leaked memory ==2309== ==2309== For counts of detected and suppressed errors, rerun with: -v ==2309== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 19 from 8) the code: #include <stdio.h> #include <sys/mman.h> #include <errno.h> #include <string.h> const size_t PAGE_SIZE = 1 << 12; int main() { unsigned start = 0; char* p =(char*) mmap(&start,PAGE_SIZE,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0); *p = 1; munmap(p,PAGE_SIZE); } --
------------------------------------------------------------------------------
_______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users