Skip to content

Commit 8adf2d7

Browse files
authored
fix(Core/Globals): Frees observer callbacks at destruction (#127)
fixes:#115
1 parent 1d9fc03 commit 8adf2d7

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

inkcpp/globals_impl.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ class globals_impl final
3636
// Initializes a new global store from the given story
3737
globals_impl(const story_impl*);
3838

39-
virtual ~globals_impl() {}
39+
virtual ~globals_impl()
40+
{
41+
for (const auto& callback : _callbacks) {
42+
delete callback.operation;
43+
}
44+
}
4045

4146
snapshot* create_snapshot() const override;
4247

inkcpp/include/functional.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class callback_base
2626
{
2727
public:
2828
virtual void call(ink::runtime::value, ink::optional<ink::runtime::value>) = 0;
29+
virtual ~callback_base() = default;
2930
};
3031

3132
template<typename F>
@@ -313,8 +314,8 @@ class function_array_delegate : public function_base
313314
char* ptr = buffer;
314315
while (*src != '\0')
315316
*(ptr++) = *(src++);
316-
*ptr = 0;
317-
result = ink::runtime::value(buffer);
317+
*ptr = 0;
318+
result = ink::runtime::value(buffer);
318319
}
319320
push(stack, result);
320321
}

0 commit comments

Comments
 (0)