Fix memory leak in sdbListKeys. (#1695)

This commit is contained in:
karliss 2019-07-29 00:42:25 +03:00 committed by GitHub
parent 329a9b6da1
commit 5dc5fe1cee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -219,6 +219,12 @@ QList<QString> CutterCore::sdbList(QString path)
return list;
}
using SdbListPtr = std::unique_ptr<SdbList, decltype (&ls_free)>;
static SdbListPtr makeSdbListPtr(SdbList *list)
{
return {list, ls_free};
}
QList<QString> CutterCore::sdbListKeys(QString path)
{
CORE_LOCK();
@ -227,7 +233,7 @@ QList<QString> CutterCore::sdbListKeys(QString path)
if (root) {
void *vsi;
ls_iter_t *iter;
SdbList *l = sdb_foreach_list(root, false);
SdbListPtr l = makeSdbListPtr(sdb_foreach_list(root, false));
ls_foreach(l, iter, vsi) {
SdbKv *nsi = (SdbKv *)vsi;
list << reinterpret_cast<char *>(nsi->base.key);
@ -2098,7 +2104,7 @@ QList<QString> CutterCore::getAllAnalClasses(bool sorted)
{
QList<QString> ret;
SdbList *l = r_anal_class_get_all(core_->anal, sorted);
SdbListPtr l = makeSdbListPtr(r_anal_class_get_all(core_->anal, sorted));
if (!l) {
return ret;
}
@ -2110,7 +2116,6 @@ QList<QString> CutterCore::getAllAnalClasses(bool sorted)
auto kv = reinterpret_cast<SdbKv *>(entry);
ret.append(QString::fromUtf8(reinterpret_cast<const char *>(kv->base.key)));
}
ls_free(l);
return ret;
}