Help - Search - Members - Calendar
Full Version: Should I release the reader in the destructor?
Hydrogenaudio Forums > Hosted Forums > foobar2000 > Development - (fb2k)
oshah
Foobar2000 0.8.3.

I have a special input plugin that manufactures its own reader_limited from the input reader. This works as expected. Once the class is destructed, I do what the SDK does and call reader_release_safe() on the reader. However, when I call this function, Foobar2000 then proceeds to crash. The crash bears all the hallmarks of performing a double delete.

CODE

reader_limited *rLimited;
virtual ~input_wad()
{
 if(this->rLimited != NULL) this->rLimited->reader_release_safe(); /* Commenting this out makes everything fine. */
 delete this->rLimited; /* Crashes here */
}


If I comment out the line that says reader_release_safe, everything works as normal. That indicates that I shouldn't be calling reader_release_safe(). However, I'm concerned that by not calling release, I'm leaking resources. Is this worry unfounded?

What's the proper procedure for creating and using a reader?

JackieKu
QUOTE(oshah @ Aug 27 2005, 12:21 AM)
Foobar2000 0.8.3.

I have a special input plugin that manufactures its own reader_limited from the input reader. This works as expected. Once the class is destructed, I do what the SDK does and call reader_release_safe() on the reader. However, when I call this function, Foobar2000 then proceeds to crash. The crash bears all the hallmarks of performing a double delete.

CODE

reader_limited *rLimited;
virtual ~input_wad()
{
 if(this->rLimited != NULL) this->rLimited->reader_release_safe(); /* Commenting this out makes everything fine. */
 delete this->rLimited; /* Crashes here */
}


If I comment out the line that says reader_release_safe, everything works as normal. That indicates that I shouldn't be calling reader_release_safe(). However, I'm concerned that by not calling release, I'm leaking resources. Is this worry unfounded?

What's the proper procedure for creating and using a reader?
*



I think it should be

CODE

reader_limited *rLimited;
virtual ~input_wad()
{
 if (this->rLimited != NULL)
    this->rLimited->reader_release_safe();
}


Since the reader has a reference counter, and it delete itself when the reference counter reaches zero.
oshah
Now this is interesting... I've been initializing the reader with operator new. However, since my DLL uses a different heap to Foobar2000 (as explained here), mixing of new/deletes between different modules will cause crashes. Does this mean my use of new is wrong?

My next question is then: how do I correctly create a reader?

CODE
/* My code is currently something like this: */
this->rLimited = new service_impl_p3_t<reader_limited, reader *, __int64, __int64>(rIn, start, end);

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.