Skip to content

Commit

Permalink
At least avoid leaking the VFBs when plugin or host is leaking.
Browse files Browse the repository at this point in the history
  • Loading branch information
pylorak committed Mar 14, 2015
1 parent 3cb1122 commit 422aae8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions avs_core/core/avisynth.cpp
Expand Up @@ -736,21 +736,36 @@ ScriptEnvironment::~ScriptEnvironment() {
while (global_var_table)
PopContextGlobal();

// We collect a list of allocated VFBs here
std::unordered_set<VideoFrameBuffer*> vfb_set;
vfb_set.reserve(FrameRegistry.size());

// Delete all VideoFrame objects
const FrameRegistryType::iterator end_it = FrameRegistry.end();
for (
FrameRegistryType::iterator it = FrameRegistry.begin();
it != end_it;
++it)
{
VideoFrame *frame = it->second;
assert(frame->refcount == 0);

if (frame->vfb->refcount == 0)
delete frame->vfb;
vfb_set.insert(frame->vfb);
frame->vfb = 0;

delete frame;
//assert(0 == frame->refcount);
if (0 == frame->refcount)
{
delete frame;
}
}

// Delete all VFBs
for (const auto& vfb : vfb_set)
{
//assert(0 == vfb->refcount);
delete vfb;
}

delete plugin_manager;
delete [] vsprintf_buf;

Expand Down
2 changes: 1 addition & 1 deletion avs_core/include/avisynth.h
Expand Up @@ -534,7 +534,7 @@ class VideoFrameBuffer {

class VideoFrame {
volatile long refcount;
VideoFrameBuffer* const vfb;
VideoFrameBuffer* vfb;

// Due to technical reasons these members are not const, but should be treated as such.
// That means do not modify them once the class has been constructed.
Expand Down

0 comments on commit 422aae8

Please sign in to comment.