Re: c4_Bytes destructor causes memory deallocation failure
Arto Stimms <[email protected]>
| Newsgroups | gmane.comp.db.metakit |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I have a followup to the c4_Bytes problem.
It seems that the destructor releases the wrong
memory.
In the debug build it gives an assertion at the
deallocation, but in a release build it gives no
error.
This just makes it worse though, since it may later
try to use the released memory, causing a crash.
Check this example program which on my machine fails
after the fourth iteration:
#include "mk4.h"
#include <string>
#include <iostream>
using namespace std;
void main() {
c4_Storage storage("datafile.kit", true);
c4_View v = storage.GetAs("v[b:B]");
v.Add(c4_Row());
c4_BytesProp pBytes("b");
string teststring("Hello, this is a test!"); //
len=22
c4_Bytes textbytes(teststring.data(),
teststring.length());
for (int i=0;i < 100;++i) {
cout << i << endl;
c4_Bytes newbytes = pBytes(v[0]).Access(0, 17);
pBytes(v[0]).Modify(textbytes, 0, textbytes.Size());
}
}
I am using metakit 2.4.9.3 with the modify patch on
windows.
Best Regards,
Arto Stimms
--- [email protected] wrote:
> I have another problem with c4_Bytes. It seems that
> the destructor in some cases deletes the wrong
> memory.
>
> The following code works as release build, but as
> debug build it fails in _CrtIsValidHeapPointer.
>
> Curiously enough it works correctly as long as the
> length is <= 16?
>
> #include "mk4.h"
> #include <string>
> #include <iostream>
> using namespace std;
>
> void main() {
> c4_Storage storage("datafile.kit", true);
> c4_View v = storage.GetAs("v[b:B]");
>
> v.Add(c4_Row());
> c4_BytesProp pBytes("b");
>
> string teststring("Hello, this is a test!"); //
> len=22
> c4_Bytes textbytes(teststring.data(),
> teststring.length());
>
> pBytes(v[0]).Modify(textbytes, 0,
> textbytes.Size());
>
> // Works with up-to len=16
> c4_Bytes newbytes = pBytes(v[0]).Access(0, 16);
> //cout << string((const char *)newbytes.Contents(),
> newbytes.Size()) << endl;
>
> newbytes = pBytes(v[0]).Access(0, 17);
> //cout << string((const char *)newbytes.Contents(),
> newbytes.Size()) << endl;
> }
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_____________________________________________
Metakit mailing list - [email protected]
http://www.equi4.com/mailman/listinfo/metakit