1

I'm using valgrind's memcheck on my soft;But I have problems in this: for some reason we will transform the malloced pointer before store,and transform back when use.Just like this:

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;
Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
wchunyu
  • 11
  • 3

1 Answers1

0

That's something that valgrind can't properly detect. Thus, you will have to write a suppression file that ignores the corresponding function.

Also, it's generally discouraged to do what you're doing, because free specifically demands that what you free is something that you got per malloc; now +1-1 seems to be a NOP to me, too, but I suspect you do something more complex in the back hand.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94