Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load_file() 中也有遗漏 delete 处 #2

Open
xuhao531799712 opened this issue Jan 6, 2021 · 2 comments
Open

load_file() 中也有遗漏 delete 处 #2

xuhao531799712 opened this issue Jan 6, 2021 · 2 comments

Comments

@xuhao531799712
Copy link

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();
   ...
}
@youngyangyang04
Copy link
Owner

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();
   ...
}

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

@join-c-meng
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants