From fb71edd45b2473bf0ac502c777a1850fb564087e Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Thu, 7 Jan 2021 01:05:12 +0000 Subject: Fix container and string leaks Some functions return a new instance of such containers, but instead we made a copy of them, without taking ownership of the original created by the function. Now we use a specific constructor taking ownership on the godot_* struct. --- src/core/NodePath.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/core/NodePath.cpp') diff --git a/src/core/NodePath.cpp b/src/core/NodePath.cpp index 37ab2a3..bc069b7 100644 --- a/src/core/NodePath.cpp +++ b/src/core/NodePath.cpp @@ -27,8 +27,7 @@ NodePath::NodePath(const char *contents) { String NodePath::get_name(const int idx) const { godot_string str = godot::api->godot_node_path_get_name(&_node_path, idx); - - return *(String *)&str; + return String(str); } int NodePath::get_name_count() const { @@ -37,7 +36,7 @@ int NodePath::get_name_count() const { String NodePath::get_subname(const int idx) const { godot_string str = godot::api->godot_node_path_get_subname(&_node_path, idx); - return *(String *)&str; + return String(str); } int NodePath::get_subname_count() const { @@ -54,17 +53,16 @@ bool NodePath::is_empty() const { NodePath NodePath::get_as_property_path() const { godot_node_path path = godot::core_1_1_api->godot_node_path_get_as_property_path(&_node_path); - return *(NodePath *)&path; + return NodePath(path); } String NodePath::get_concatenated_subnames() const { godot_string str = godot::api->godot_node_path_get_concatenated_subnames(&_node_path); - return *(String *)&str; + return String(str); } NodePath::operator String() const { godot_string str = godot::api->godot_node_path_as_string(&_node_path); - - return *(String *)&str; + return String(str); } bool NodePath::operator==(const NodePath &other) { -- cgit v1.2.3