yhirose/cpp-httplib

Memory leak at line# 9390 "0.16.0"

OneMeanDragon opened this issue · 3 comments

        const /*static*/ std::regex re(
            R"((?:([a-z]+):\/\/)?(?:\[([a-fA-F\d:]+)\]|([^:/?#]+))(?::(\d+))?)");

the static regex object is not getting released. temporary fix above.

another in the httplib::Response somewhere thats is currently eluding me heh.
edit: 7/11/24
well narrowed it down to the static variables removing the static (as done above) regexvars/strings/std objects in general removed the memory leak, problem is didnt write down which ones heh.

int main() { /* these are regular http requests non crypt */
#ifdef _DEBUG
	int nOldState = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
	_CrtSetDbgFlag(nOldState | _CRTDBG_ALLOC_MEM_DF);
#endif
    bool test1 = false; /* post 1 fixed that leak */
    bool test2 = true;
    if(test1) {
        std::shared_ptr<httplib::Client> cli = std::make_shared<httplib::Client>(VALID_URL_GOES_HERE);
    } else {
    if(test2) {
        std::shared_ptr<httplib::Client> cli = std::make_shared<httplib::Client>(VALID_URL_GOES_HERE);
        std::string szRequest = std::vformat("{}", std::make_format_args(VALID_EXTENSION_FILE_GOES_HERE));
        httplib::Result res(cli->Get(szRequest));
    } }
#ifdef _DEBUG
	_CrtDumpMemoryLeaks();
#endif
}

Why are you considering a static object a memory leak? It's obvious it won't be released, that's part of what static is supposed to do.

@OneMeanDragon as @sum01 mentioned, I don't consider this situation as memory leak, and I would like to keep them as static for performance reason. Thanks for your understanding.