Skip to content

Commit

Permalink
Fix memory leak (#6) and copy frame properties for VS (#7) and AVS+
Browse files Browse the repository at this point in the history
  • Loading branch information
Asd-g authored and msg7086 committed May 25, 2021
1 parent f979f01 commit 87da17c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 7 additions & 4 deletions include/dualsynth/ds_frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ struct DSFrame
const VSFrameRef* copy_frames[1] {ToVSFrame()};
int copy_planes[4] = {0};
auto vsframe = copy ?
_vsapi->newVideoFrame2(_vsformat, FrameWidth, FrameHeight, copy_frames, copy_planes, NULL, const_cast<VSCore*>(_vscore)) :
_vsapi->newVideoFrame(_vsformat, FrameWidth, FrameHeight, NULL, const_cast<VSCore*>(_vscore));
_vsapi->newVideoFrame2(_vsformat, FrameWidth, FrameHeight, copy_frames, copy_planes, ToVSFrame(), const_cast<VSCore*>(_vscore)) :
_vsapi->newVideoFrame(_vsformat, FrameWidth, FrameHeight, ToVSFrame(), const_cast<VSCore*>(_vscore));
_vsapi->freeFrame(copy_frames[0]);

DSFrame new_frame(vsframe, _vscore, _vsapi);
Expand All @@ -101,7 +101,7 @@ struct DSFrame
DSFrame Create(DSVideoInfo vi) {
planes = vi.Format.IsFamilyYUV ? planes_y : planes_r;
if (_vsapi) {
auto vsframe = _vsapi->newVideoFrame(vi.Format.ToVSFormat(_vscore, _vsapi), vi.Width, vi.Height, NULL, const_cast<VSCore*>(_vscore));
auto vsframe = _vsapi->newVideoFrame(vi.Format.ToVSFormat(_vscore, _vsapi), vi.Width, vi.Height, ToVSFrame(), const_cast<VSCore*>(_vscore));
DSFrame new_frame(vsframe, _vscore, _vsapi);
new_frame._vsdst = vsframe;
new_frame.DstPointers = new unsigned char*[Format.Planes];
Expand All @@ -111,7 +111,10 @@ struct DSFrame
}
else if (_env) {
auto avsvi = vi.ToAVSVI();
auto new_avsframe = _env->NewVideoFrame(avsvi);
bool has_at_least_v8 = true;
try { _env->CheckVersion(8); }
catch (const AvisynthError&) { has_at_least_v8 = false; }
auto new_avsframe = (has_at_least_v8) ? _env->NewVideoFrameP(avsvi, &_avssrc) : _env->NewVideoFrame(avsvi);
auto dstp = new unsigned char*[Format.Planes];
for (int i = 0; i < Format.Planes; i++)
dstp[i] = new_avsframe->GetWritePtr(planes[i]);
Expand Down
6 changes: 4 additions & 2 deletions src/f3kdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#pragma once

#include <memory>

#ifdef HAS_EXECUTION
#include <execution>
#endif
Expand All @@ -30,7 +32,7 @@ int GetCPUFlags();

struct F3KDB final : Filter {
f3kdb_params_t ep;
f3kdb_core_t* engine;
std::unique_ptr<f3kdb_core_t> engine;
InDelegator* _in;
bool crop;
char error_msg[1024];
Expand Down Expand Up @@ -178,7 +180,7 @@ struct F3KDB final : Filter {

try
{
engine = new f3kdb_core_t(in_vi, ep, opt);
engine = std::make_unique<f3kdb_core_t>(in_vi, ep, opt);
} catch (std::bad_alloc&) {
throw "Memory allocation failed";
}
Expand Down

0 comments on commit 87da17c

Please sign in to comment.