Skip to content

Commit f3db5d5

Browse files
committed
Fix memory leak in yoga
1 parent 3e9f675 commit f3db5d5

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

thirdparty/rive/rive.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
license: MIT
3434
3535
dependencies: harfbuzz sheenbidi yoga_library
36-
defines: WITH_RIVE_TEXT=1 WITH_RIVE_YOGA=1 WITH_RIVE_LAYOUT=1 WITH_RIVE_TOOLS=1
36+
defines: WITH_RIVE_TEXT=1 WITH_RIVE_YOGA=1 WITH_RIVE_LAYOUT=1
3737
appleFrameworks: CoreText
3838
searchpaths: include
3939

thirdparty/yoga_library/upstream/yoga/Yoga.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,27 @@ YOGA_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) {
197197
return node;
198198
}
199199

200+
namespace {
201+
struct YogaWrapperWithCleanup {
202+
YogaWrapperWithCleanup()
203+
: defaultConfig (YGConfigNew())
204+
{
205+
}
206+
207+
~YogaWrapperWithCleanup() {
208+
if (defaultConfig != nullptr) {
209+
YGConfigFree (defaultConfig);
210+
defaultConfig = nullptr;
211+
}
212+
}
213+
214+
YGConfigRef defaultConfig = nullptr;
215+
};
216+
} // namespace
217+
200218
YOGA_EXPORT YGConfigRef YGConfigGetDefault() {
201-
static YGConfigRef defaultConfig = YGConfigNew();
202-
return defaultConfig;
219+
static YogaWrapperWithCleanup defaultWrapper = YogaWrapperWithCleanup();
220+
return defaultWrapper.defaultConfig;
203221
}
204222

205223
YOGA_EXPORT YGNodeRef YGNodeNew(void) {

thirdparty/yoga_library/yoga_library.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
version: 2.0.1
3030
name: A portable layout engine targeting web standards
3131
description: A portable layout engine targeting web standards.
32-
website: https://www.zlib.net/
32+
website: https://github.com/facebook/yoga
3333
license: Public Domain
3434
3535
searchpaths: upstream

0 commit comments

Comments
 (0)