[libraries/cxx-rust-cssparser] cpp: Fix leaking stylesheet
Nicolas Fella <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit a3b605a5633857f3f6a4df1b41c4703408515902 by Nicolas Fella.
Committed on 03/08/2026 at 15:02.
Pushed by nicolasfella into branch 'master'.
Fix leaking stylesheet
We get a Box object from Rust, which is comparable to a unique_ptr.
Currently we release it, and then never free the memory.
Instead hold on to the actual box object until we don't need it any
more, freeing the memory.
M +8 -6 cpp/CssParser.cpp
https://invent.kde.org/libraries/cxx-rust-cssparser/-/commit/a3b605a5633857f3f6a4df1b41c4703408515902
diff --git a/cpp/CssParser.cpp b/cpp/CssParser.cpp
index c6c066f..1cdfdfe 100644
--- a/cpp/CssParser.cpp
+++ b/cpp/CssParser.cpp
@@ -52,23 +52,25 @@ Rule Rule::fromRust(const rust::StyleRule &rule)
struct StyleSheet::Private
{
+ Private(std::filesystem::path path)
+ : path(path)
+ , stylesheet(rust::create_stylesheet(path.string()))
+ {
+ }
+
void update();
std::filesystem::path path;
- rust::StyleSheet *stylesheet;
+ ::rust::Box<rust::StyleSheet> stylesheet;
std::vector<Rule> rules;
std::vector<Error> errors;
std::vector<std::filesystem::path> paths;
};
StyleSheet::StyleSheet(const std::filesystem::path &path)
- : d(std::make_unique<Private>())
+ : d(std::make_unique<Private>(path))
{
- d->path = path;
-
- auto sheet = rust::create_stylesheet(path.string());
- d->stylesheet = sheet.into_raw();
}
StyleSheet::~StyleSheet() = default;