Removing memory-leak, fixes #83. (#85)

Co-authored-by: morgan.szygenda <morgan.szygenda@scle.fr>
This commit is contained in:
mszy 2021-09-22 04:50:33 +02:00 committed by GitHub
parent cda80854eb
commit d386bb96b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 8 deletions

View File

@ -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};
}