From b086d0612740978c1942c1c3a078d4a0b8ffffef Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 21 Dec 2020 22:09:42 -0800 Subject: [clang-tidy] cpp: Replace free with delete It's the C++ way. It also avoids having to check for NULL. Found with cppcoreguidelines-owning-memory Signed-off-by: Rosen Penev --- src/Data.cpp | 2 +- src/Dictionary.cpp | 4 ++-- src/Key.cpp | 9 ++------- src/String.cpp | 9 ++------- src/Structure.cpp | 4 ++-- 5 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/Data.cpp b/src/Data.cpp index 4515388..a96fc50 100644 --- a/src/Data.cpp +++ b/src/Data.cpp @@ -70,7 +70,7 @@ std::vector Data::GetValue() const uint64_t length = 0; plist_get_data_val(_node, &buff, &length); std::vector ret(buff, buff + length); - free(buff); + delete buff; return ret; } diff --git a/src/Dictionary.cpp b/src/Dictionary.cpp index 20e9710..ea04e81 100644 --- a/src/Dictionary.cpp +++ b/src/Dictionary.cpp @@ -39,7 +39,7 @@ static void dictionary_fill(Dictionary *_this, std::map &map, plist_dict_next_item(node, it, &key, &subnode); if (key && subnode) map[std::string(key)] = Node::FromPlist(subnode, _this); - free(key); + delete key; } while (subnode); free(it); } @@ -156,7 +156,7 @@ void Dictionary::Remove(Node* node) plist_dict_get_item_key(node->GetPlist(), &key); plist_dict_remove_item(_node, key); std::string skey = key; - free(key); + delete key; _map.erase(skey); delete node; } diff --git a/src/Key.cpp b/src/Key.cpp index 8ba497a..5d7d372 100644 --- a/src/Key.cpp +++ b/src/Key.cpp @@ -67,13 +67,8 @@ std::string Key::GetValue() const { char* s = NULL; plist_get_key_val(_node, &s); - std::string ret; - if (s) { - ret = s; - free(s); - } else { - ret = ""; - } + std::string ret = s ? s : ""; + delete s; return ret; } diff --git a/src/String.cpp b/src/String.cpp index cd4f98f..06b61ba 100644 --- a/src/String.cpp +++ b/src/String.cpp @@ -67,13 +67,8 @@ std::string String::GetValue() const { char* s = NULL; plist_get_string_val(_node, &s); - std::string ret; - if (s) { - ret = s; - free(s); - } else { - ret = ""; - } + std::string ret = s ? s : ""; + delete s; return ret; } diff --git a/src/Structure.cpp b/src/Structure.cpp index 9445c23..4be4e7d 100644 --- a/src/Structure.cpp +++ b/src/Structure.cpp @@ -56,7 +56,7 @@ std::string Structure::ToXml() const uint32_t length = 0; plist_to_xml(_node, &xml, &length); std::string ret(xml, xml+length); - free(xml); + delete xml; return ret; } @@ -66,7 +66,7 @@ std::vector Structure::ToBin() const uint32_t length = 0; plist_to_bin(_node, &bin, &length); std::vector ret(bin, bin+length); - free(bin); + delete bin; return ret; } -- cgit v1.1-32-gdbae