valgrind --log-file=/home/valgrind-mysql.log --error-limit=no ./mysqld-debug --defaults-file=/home/mysqldata/3306/my.cnf --user=mysql
重点看HEAP SUMMARY、Invalid free、Invalid read、Invalid write.
- 如果malloc/realloc/calloc和free的数量不同,则会报告如下的内容。
==3375== HEAP SUMMARY:
==3375== in use at exit: 128 bytes in 1 blocks
==3375== total heap usage: 4,900 allocs, 4,899 frees, 29,477,380 bytes allocated
- 多次free的问题
==3375== Invalid free() / delete / delete[] / realloc()
==3375== at 0x4C2BD57: free (vg_replace_malloc.c:530)
==3375== by 0x4005AA: aa (a.c:9)
==3375== by 0x4005BA: main (main.c:14)
- 非法内存操作:
==3375== Invalid write of size 4
==3375== at 0x40059B: aa (a.c:8)
==3375== by 0x4005BC: main (main.c:14)
==3375== Address 0x51fc044 is 0 bytes after a block of size 4 alloc'd
==3375== at 0x4C2AC3D: malloc (vg_replace_malloc.c:299)
==3375== by 0x40058E: aa (a.c:7)
==3375== by 0x4005BC: main (main.c:14)如上表示,使用malloc申请了4个字节的内存,但在a.c的第8行,对第4(从0开始计数)个字节进行了写操作。