Richard M. Ulrich
2008-07-27 21:09:05 UTC
Hello,
I'm using C-Builder 2007, Windows XP SP3. I have a program that contains a
relatively simple thread, and it also contains a module that defines a
global variable which is a structure, several entries of which are
AnsiStrings. One of those AnsiStrings are getting corrupted when the thread
is terminated by the following function, and I can't see why.
void __fastcall TMainForm::RestartMonitoring(void)
{
CheckMemory(); //This passes, gl_Options.caseFileName is intact
if (OutputMonitor) {
try {
OutputMonitor->OnTerminate = NULL; //We don't want to trigger the
auto-restart code
OutputMonitor->Terminate();
CheckMemory(); //this fails, gl_Options.caseFileName has been
mangled
} catch (...) {
}
}
...
}
More data: FreeOnTerminate is true; the corruption appears to involve just
two bytes getting changed; if I comment out the OnTerminate = NULL line,
the corruption is just one byte; the thread class does not include the
header file that defines gl_Options, so it ought not be able to touch that
memory; setting a data breakpoint does not trap the change.
I suppose I'll just stop using AnsiStrings and see if the problem goes away,
but I wonder if anyone has run into something like this before, where the
shared memory pool for AnsiStrings appears to get corrupted (assuming that
is the problem).
R
I'm using C-Builder 2007, Windows XP SP3. I have a program that contains a
relatively simple thread, and it also contains a module that defines a
global variable which is a structure, several entries of which are
AnsiStrings. One of those AnsiStrings are getting corrupted when the thread
is terminated by the following function, and I can't see why.
void __fastcall TMainForm::RestartMonitoring(void)
{
CheckMemory(); //This passes, gl_Options.caseFileName is intact
if (OutputMonitor) {
try {
OutputMonitor->OnTerminate = NULL; //We don't want to trigger the
auto-restart code
OutputMonitor->Terminate();
CheckMemory(); //this fails, gl_Options.caseFileName has been
mangled
} catch (...) {
}
}
...
}
More data: FreeOnTerminate is true; the corruption appears to involve just
two bytes getting changed; if I comment out the OnTerminate = NULL line,
the corruption is just one byte; the thread class does not include the
header file that defines gl_Options, so it ought not be able to touch that
memory; setting a data breakpoint does not trap the change.
I suppose I'll just stop using AnsiStrings and see if the problem goes away,
but I wonder if anyone has run into something like this before, where the
shared memory pool for AnsiStrings appears to get corrupted (assuming that
is the problem).
R