So I've been tracking some memory issue for the longest time. I'm coding in C++ and I can see that my program mostly works. I am monitoring my resources and I dont think I have a memory leak because my memory used stays below 12% (I'm on a system with 256MB memory). I can let this thing run for hours and it works but eventually it segfaults.
It is hard to anaylize this issue because it takes so long for an issue to actually come up. It just crashed after running it in a debugger all day and I can see that I am doing some work on what should be a valid pointer address.
sprintf(asciihex, "%x", var[c] & MASK); //Where var is a pointer //MASK is 0xff
I know this works because my program runs with valid info for hours, but when the program crashes, instead of my var being a valid pointer (0xbb6b03408), the memory address is (0x10).
Also other variables (it is part of a struct) are actually NULLed. So I am trying to figure out what is going on here. My code has a check for NULL pointers and skips over them but 0x10 isn't considered NULL so it breaks. I've seen other values like 0x15 and 0x18 so I dont want to just add more checks for those, I want to find the root cause.
Any suggestions would be great!