Any debea user around?? I think I found a bug!  [SOLVED]

In this forum you can discuss database related issues which can be wxWidgets related, but also generic in nature.
maxbld
Earned some good credits
Earned some good credits
Posts: 111
Joined: Wed Jan 30, 2013 10:49 pm

Any debea user around?? I think I found a bug!

Postby maxbld » Fri May 17, 2013 10:21 am

Dear all,

debea-users group is inactive since long, I tried to post this topic there, but had no luck. What's up with debea? It looks like a great piece of code and wxWidgets sponsors it as a replacement for wxODBC (see http://wiki.wxwidgets.org/ODBC). How comes I seem to be the only active debea user? Is it becouse ODBC is dead meat? C'mon ODBC isn't that bad!

Does anybody know if there's any active debea forum??

Anyway, please let me try to ask here... I could have found a bug, but I'm not sure... I'd like to ask advice to someone who's expert on debea library or in C++ in general :) . sqlarchive.cpp has the following code:

Code: Select all

SQLIStream
SQLArchive::getIStream() {
  DbConnection* conn = getFreeConnection();
  SQLIStream stream(conn,&mFilterMapper);
  return stream;
};


OStream*
SQLArchive::getOutputStream() {
  DbConnection* conn = getFreeConnection();
  SQLOStream* stream = new SQLOStream(conn,mFetcher,&mFilterMapper);
  return stream;
};


As you may notice OStream is a pointer, IStream is a value. In my code I get the input stream several times from archives pointing to the same ODBC DSN and I always get the same stream (same pointer inside) which I use to construct many instances of the same dba::SQLIStream derived class.

Code: Select all

RSetData::RSetData(const dba::SQLIStream& pStream, Store *RSet, wxString tabName)
            :   dba::SQLIStream(pStream)
{
    int j = 0;
    mapList mapRow;

    dba::Stream::open(*RSet, tabName);
...
}


All works well until it's time to destroy the objects: the first delete goes smooth, all the others throw an exception because the heap is corrupted.

My hypothesis is that if I would have got a pointer from SQLArchive::getIStream() , everything would have been well since I would have got distinct instances of the IStream. what do you say, am I right or just a daydreamer?

BR,
Max.

User avatar
doublemax
Moderator
Moderator
Posts: 11536
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Any debea user around?? I think I found a bug!

Postby doublemax » Fri May 17, 2013 10:45 am

I don't really see the (API)-connection between SQLIStream and OStream here.

SQLArchive::getOutputStream returns a pointer to an object created with "new". It's your responsibility to delete it. This means that it's also your responsibility to make sure that it's not deleted more than once.

How this happens is unclear from the information you posted.
Use the source, Luke!

maxbld
Earned some good credits
Earned some good credits
Posts: 111
Joined: Wed Jan 30, 2013 10:49 pm

Re: Any debea user around?? I think I found a bug!

Postby maxbld » Fri May 17, 2013 1:06 pm

I'm deriving from SQLIStream: RSetData derives from SQLIStream, as you can see by its constructor:

Code: Select all

RSetData::RSetData(const dba::SQLIStream& pStream, Store *RSet, wxString tabName)
            :   dba::SQLIStream(pStream)
{


My problem is that when I destroy the second instance of RSetData* of the several I created, the destructor of the base class dba::SQLIStream is called and tries to delete the object pointed by pStream, but since SQLIStream SQLArchive::getIStream() always gives back the same object, the second try to delete it corrupts the heap.

At least this is what I understood.

And I'm unable to find a way to induce SQLArchive::getIStream() to gimme every time a new SQLIStream.

So what I wonder is if the method was like follows:

Code: Select all

SQLIStream*
SQLArchive::getIStream() {
  DbConnection* conn = getFreeConnection();
  SQLIStream* stream = new SQLIStream(conn,&mFilterMapper);
  return stream;
};

Wouldn't I solve my problem?

Thanks, BR,
Max.

User avatar
doublemax
Moderator
Moderator
Posts: 11536
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Any debea user around?? I think I found a bug!  [SOLVED]

Postby doublemax » Fri May 17, 2013 1:44 pm

Code: Select all

const dba::SQLIStream& pStream
pStream is a const reference. The dba::SQLIStream dtor cannot delete it ( at least not without some dirty tricks ). That must happen somewhere else. Or the crash is caused by something else.
Use the source, Luke!

maxbld
Earned some good credits
Earned some good credits
Posts: 111
Joined: Wed Jan 30, 2013 10:49 pm

Re: Any debea user around?? I think I found a bug!

Postby maxbld » Fri May 17, 2013 5:40 pm

Yes. You hit exactly the point!

Solution was not to derive RSetData any more from SQLIStream, but use instead an object declared directly in RSetData which class was deriving from SQLIStream, so that it had not to be deleted. This way:

Code: Select all

RSetData::RSetData(const dba::SQLIStream& pStream, Store *RSet, wxString tabName)
{
   bIStreamDeleted = false;
    CalimeroSQLIStream istream(pStream, RSet);
   m_mapArray = istream.listNames(tabName);
}


Thanks again, BR,
Max.


Return to “Database Related”

Who is online

Users browsing this forum: No registered users and 1 guest