Skip to content

Commit 37f9027

Browse files
committed
fix String::GetValue memory leaking and suport assignment of const char*
1 parent 44099d4 commit 37f9027

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

include/plist/String.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public :
3535
String(plist_t node, Node* parent = NULL);
3636
String(const String& s);
3737
String& operator=(const String& s);
38+
String& operator=(const char* s);
3839
String(const std::string& s);
3940
virtual ~String();
4041

src/String.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ String& String::operator=(const PList::String& s)
4545
return *this;
4646
}
4747

48+
String& String::operator=(const char* s)
49+
{
50+
plist_free(_node);
51+
_node = plist_new_string(s);
52+
return *this;
53+
}
54+
4855
String::String(const std::string& s) : Node(PLIST_STRING)
4956
{
5057
plist_set_string_val(_node, s.c_str());
@@ -69,7 +76,7 @@ std::string String::GetValue() const
6976
char* s = NULL;
7077
plist_get_string_val(_node, &s);
7178
std::string ret = s ? s : "";
72-
delete s;
79+
free((void*)s);
7380
return ret;
7481
}
7582

0 commit comments

Comments
 (0)