Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在我的软件上使用了 valgrind 的 memcheck;但是我有一个问题:出于某种原因,我们将在存储之前转换 malloced 指针,并在使用时转换回来。就像这样:
char* ptr = (char*)malloc(1); ptr = ptr + 1; ...... origin_ptr = ptr -1; free(origin_ptr); ptr = ptr + 1; <------ this will make valgrind to report memory lost;
这是 valgrind 无法正确检测到的。因此,您将不得不编写一个忽略相应功能的抑制文件。
此外,通常不鼓励做你正在做的事情,因为free特别要求你免费的东西是你得到的东西malloc;现在+1-1对我来说似乎也是一个 NOP,但我怀疑你在背后做了一些更复杂的事情。
free
malloc
+1-1