@@ -328,6 +328,12 @@ namespace Automation4 {
328328 return result;
329329 }
330330
331+ std::unique_ptr<AssEntry> LuaAssFile::LuaToTrackedAssEntry (lua_State *L) {
332+ std::unique_ptr<AssEntry> e = LuaToAssEntry (L, ass);
333+ allocated_lines.push_back (e.get ());
334+ return e;
335+ }
336+
331337 int LuaAssFile::ObjectIndexRead (lua_State *L)
332338 {
333339 switch (lua_type (L, 2 )) {
@@ -453,7 +459,7 @@ namespace Automation4 {
453459 // insert
454460 CheckBounds (n);
455461
456- auto e = LuaToAssEntry (L, ass );
462+ auto e = LuaToTrackedAssEntry (L );
457463 modification_type |= modification_mask (e.get ());
458464 QueueLineForDeletion (n - 1 );
459465 AssignLine (n - 1 , std::move (e));
@@ -542,7 +548,7 @@ namespace Automation4 {
542548
543549 for (int i = 1 ; i <= n; i++) {
544550 lua_pushvalue (L, i);
545- auto e = LuaToAssEntry (L, ass );
551+ auto e = LuaToTrackedAssEntry (L );
546552 modification_type |= modification_mask (e.get ());
547553
548554 if (lines.empty ()) {
@@ -586,7 +592,7 @@ namespace Automation4 {
586592 new_entries.reserve (n - 1 );
587593 for (int i = 2 ; i <= n; i++) {
588594 lua_pushvalue (L, i);
589- auto e = LuaToAssEntry (L, ass );
595+ auto e = LuaToTrackedAssEntry (L );
590596 modification_type |= modification_mask (e.get ());
591597 InsertLine (new_entries, i - 2 , std::move (e));
592598 lua_pop (L, 1 );
@@ -625,7 +631,7 @@ namespace Automation4 {
625631
626632 int LuaAssFile::LuaParseKaraokeData (lua_State *L)
627633 {
628- auto e = LuaToAssEntry (L, ass );
634+ auto e = LuaToTrackedAssEntry (L );
629635 auto dia = check_cast_constptr<AssDialogue>(e.get ());
630636 argcheck (L, !!dia, 1 , " Subtitle line must be a dialogue line" );
631637
@@ -734,6 +740,7 @@ namespace Automation4 {
734740 void LuaAssFile::Cancel ()
735741 {
736742 for (auto & line : lines_to_delete) line.release ();
743+ for (AssEntry *line : allocated_lines) delete line;
737744 references--;
738745 if (!references) delete this ;
739746 }
0 commit comments