BoundsChecker mis-reporting memory leak in instrumented code

0 Likes

Problem:

BoundsChecker is reporting leaks on memory that is freed later in the run.

Resolution:

BoundsChecker tracks certain operations (e.g. reassignment, arithmetic, comparisons, indexing) on pointer variables.  If the pointer is cast to a non-pointer variable (e.g. DWORD), BoundsChecker will not track those operations in statements using the non-pointer variable.

Therefore, if the following code is instrumented, BoundsChecker will report a leak leaving scope at line 5 and a leak due to reassignment at line 11, even though the memory is later deleted at line 16:

  1  void TestDWORD(DWORD nSave)

  2  {

  3    int* pInt;

  4    pInt = (int*)nSave;

  5  };

  6

  7  int main(int argc, char* argv[])

  8  {

  9     int* pInt = new int;

10    DWORD nSave = (DWORD)pInt;

11    pInt = NULL;

12

13    TestDWORD(nSave);

14

15    int* pInt = (int*)nSave;

16    delete pInt;

17

18    return 0;

19  }

Old KB# 12072
Comment List
Anonymous
Related Discussions
Recommended