Skip to content

Commit

Permalink
C++: Use free() instead of delete for C things
Browse files Browse the repository at this point in the history
  • Loading branch information
nikias committed Mar 1, 2025
1 parent d40f03e commit 5ea6de6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void Array::Remove(Node* node)
std::vector<Node*>::iterator it = _array.begin();
it += pos;
_array.erase(it);
delete node;
free(node);
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/Data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,10 @@ void Data::SetValue(const std::vector<char>& buff)

std::vector<char> Data::GetValue() const
{
char* buff = NULL;
uint64_t length = 0;
plist_get_data_val(_node, &buff, &length);
const char* buff = plist_get_data_ptr(_node, &length);
std::vector<char> ret(buff, buff + length);
delete buff;
return ret;
}



} // namespace PList
6 changes: 3 additions & 3 deletions src/Dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static void dictionary_fill(Dictionary *_this, std::map<std::string,Node*> &map,
plist_dict_next_item(node, it, &key, &subnode);
if (key && subnode)
map[std::string(key)] = Node::FromPlist(subnode, _this);
delete key;
free(key);
} while (subnode);
free(it);
}
Expand Down Expand Up @@ -176,9 +176,9 @@ void Dictionary::Remove(Node* node)
plist_dict_get_item_key(node->GetPlist(), &key);
plist_dict_remove_item(_node, key);
std::string skey = key;
delete key;
free(key);
_map.erase(skey);
delete node;
free(node);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ std::string Key::GetValue() const
char* s = NULL;
plist_get_key_val(_node, &s);
std::string ret = s ? s : "";
delete s;
free(s);
return ret;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ std::string Structure::ToXml() const
uint32_t length = 0;
plist_to_xml(_node, &xml, &length);
std::string ret(xml, xml+length);
delete xml;
free(xml);
return ret;
}

Expand All @@ -67,7 +67,7 @@ std::vector<char> Structure::ToBin() const
uint32_t length = 0;
plist_to_bin(_node, &bin, &length);
std::vector<char> ret(bin, bin+length);
delete bin;
free(bin);
return ret;
}

Expand Down

0 comments on commit 5ea6de6

Please sign in to comment.