SUNET icon indicating copy to clipboard operation
SUNET copied to clipboard

memory leak 2

Open paulpach opened this issue 7 years ago • 0 comments

I found this code:

int main() {
    
    sub_framework::Request* request = new sub_framework::Request();
    sub_framework::HttpParser* http_parser = new sub_framework::HttpParser();
    char *recv_buf = "";
    http_parser->_parse(recv_buf, *request);
    return 0;
}

Valgrind would flag that as a memory leak, consider allocating the request and parser in the stack instead:

int main() {
    
    sub_framework::Request request;
    sub_framework::HttpParser http_parser;
    char *recv_buf = "";
    http_parser->_parse(recv_buf, *request);
    return 0;
}

or use smart pointers instead of raw pointers.

paulpach avatar Jun 15 '17 15:06 paulpach