I've been working on a money management program in freepascal for quite some time and recently started to use pointers to resolve some limitations. It works fine 90% of the time. I'm trying to debug an EAccessViolation that seem to happen at random times. I checked every pointer, everywhere it's been allocated, accessed or freed, it all looks fine to me.
I've finally found a situation where it always happen and tracked down the part of the code "responsible" : a fonction that builds an ansistring that's supposed to be about 2000 chars long. I replaced it by a pchar and realised the access violation occurs when i try to allocate more than 524 char with stralloc. I can allocate as many pchar as I want as long as they're under 524 chars.
If someone has any idea how i can get an access violation without trying to read/write anything, that would be great. It's been pointed out to me THIS IS a heap corruption
I also tried to run my program on a different version of my OS (ubuntu 10, lubuntu 14) on the same computer, same problem. But using another computer, on lubuntu 14, it seems to work fine. With a few more tests I've found out that the problem occurs whatever OS or computer I use, but doesn't happen if the size of the terminal I run the program into is greater than a certain value. There might be a problem with my use of the CRT unit and more specifically the "window" function even though I don't use any pointers in my unit accessing the CRT's functions? I'm looking into it...
could it be a faulty memory ? memtest86 returned no errors ... NO
thanks for any suggestions.