youngyangyang04 / Skiplist-CPP

A tiny KV storage based on skiplist written in C++ language| 使用C++开发,基于跳表实现的轻量级键值数据库🔥🔥 🚀

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

load_file() 中也有遗漏 delete 处

xuhao531799712 opened this issue · comments

load_file() 里的 key 和 value 都是采用定义为指针然后 new 一个对象空间给它俩,但是函数最后都没有对这两个 string 指针进行 delete 操作,也是存在内存泄露的。

void SkipList<K, V>::load_file() {

    _file_reader.open(STORE_FILE);
    std::cout << "load_file-----------------" << std::endl;
    std::string line;
    std::string* key = new std::string();
    std::string* value = new std::string();
   ...
}

load_file() 里的 key 和 value 都是采用定义为指针然后 new 一个对象空间给它俩,但是函数最后都没有对这两个 string 指针进行 delete 操作,也是存在内存泄露的。

void SkipList<K, V>::load_file() {

    _file_reader.open(STORE_FILE);
    std::cout << "load_file-----------------" << std::endl;
    std::string line;
    std::string* key = new std::string();
    std::string* value = new std::string();
   ...
}

感谢指正,我抽空看一下哈

建议使用智能指针来进行优化,目前的版本check下来在vs上是有报错的