Removing memory-leak, fixes #83.
This commit is contained in:
parent
cda80854eb
commit
cf4541335c
|
|
@ -40,16 +40,14 @@ const std::chrono::high_resolution_clock::time_point etcdv3::Action::startTimepo
|
|||
}
|
||||
|
||||
std::string etcdv3::detail::string_plus_one(std::string const &value) {
|
||||
// referred from the Go implementation in etcd.
|
||||
char *s = static_cast<char *>(calloc(value.size() + 1, sizeof(char)));
|
||||
std::memcpy(s, value.c_str(), value.size());
|
||||
for (int i = value.size() - 1; i >= 0; --i) {
|
||||
if (static_cast<unsigned char>(s[i]) < 0xff) {
|
||||
// Referred from the Go implementation in etcd.
|
||||
for (int32_t i = value.size() - 1; i >= 0; --i) {
|
||||
if (static_cast<unsigned char>(value[i]) < 0xff) {
|
||||
std::string s = value.substr(0, i + 1);
|
||||
s[i] = s[i] + 1;
|
||||
std::string ret = std::string(s, i + 1);
|
||||
free(s);
|
||||
return ret;
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
return {etcdv3::NUL};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue