Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix String::GetValue memory leaking and suport assignment of const char* #256

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/plist/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public :
String(plist_t node, Node* parent = NULL);
String(const String& s);
String& operator=(const String& s);
String& operator=(const char* s);
String(const std::string& s);
virtual ~String();

Expand Down
9 changes: 8 additions & 1 deletion src/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ String& String::operator=(const PList::String& s)
return *this;
}

String& String::operator=(const char* s)
{
plist_free(_node);
_node = plist_new_string(s);
return *this;
}

String::String(const std::string& s) : Node(PLIST_STRING)
{
plist_set_string_val(_node, s.c_str());
Expand All @@ -69,7 +76,7 @@ std::string String::GetValue() const
char* s = NULL;
plist_get_string_val(_node, &s);
std::string ret = s ? s : "";
delete s;
free((void*)s);
return ret;
}

Expand Down