microsoft / cpprestsdk

The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Other
7.89k stars 1.64k forks source link

Memory leaks when inlcuding the libary in MFC project #99

Open BasConijn opened 8 years ago

BasConijn commented 8 years ago

I have created an test MFC project to remove every dependency. cpprest.zip. Compiled with visual studio 2013. I have added the project using NuGet.

After executing the project visual studio reports a lot of memory leaks. I have added visual leak detector, but that reports no leaks (First two lines of the pastebin). See http://pastebin.com/KdLDtAf6. Adding the cpprest120d_2_8.dll to the delayed dll import (linker->input) solves most of the leaks (only leaks of #67 remain).

However, I receive "cannot delay load 'cpprest120d_2_8.dll' " when using the http_client class.

When uncommenting the "CreateRequest" functions, even more memory leaks happen. These are also reported by Visual Leak Detector. See http://pastebin.com/wGWdEuBB

Anyone knows where the leaks are coming from or how I can ignore them?

nathan-gilbert commented 7 years ago

Did you ever find a solution to this problem?

BasConijn commented 7 years ago

Nope. I am not sure where to look though.

Yavathar commented 7 years ago

I'm experiencing the same memory leaks. What I have in my codes are

  1. including the head file #include <cpprest\http_client.h>
  2. in my class' method, unsigned int CMy::http_post() { web::http::http_request requestGCM(L"POST"); return 0; } Actually In runtime my codes never call the above method. But, when my program ends, a lot of memory leaks are found.

I wonder this issue will be fixed by someone?

[Adding comments] The memory leaks happen when I test with web::json::value. I only declared a valable, jsonBody like; web::json::value jsonBody; in a function that I've never called in my code.

Curry-Messi commented 6 years ago

You try

Project Properties
Linker->Input->Add library dependencies
mfc120ud.lib;mfcm120ud.lib
PversusNP commented 6 years ago

I have the same problem. I compiled cpprest140 source (version 2.10.2) with visual studio 2015 for Win32. I linked it in my MFC project and if I run the application, without calling any cpprest api, when I stop I get memory leaks. What's the solution? Thanks.

yzxandfcm commented 4 years ago

I have the same problem. How can fix this issue

Curry-Messi commented 4 years ago

you can try it like this:open "Projects->properties->Linker->input" in "Additional Dependencies" add mfc120ud.lib mfcm120ud.lib

vs2017: mfc140ud.lib mfcm140ud.lib

At 2020-05-06 12:24:18, "Jack" notifications@github.com wrote:

I have the same problem. How can fix this issue

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

yzxandfcm commented 4 years ago

Curry, Thanks for your proposal, But I used vs2019, I can NOT find any files like the mfcxxxx.lib.

Thanks.

Best Regrards, Jack Yuan

From: Curry-Messi Date: 2020-05-12 09:13 To: microsoft/cpprestsdk CC: Jack; Comment Subject: Re: [microsoft/cpprestsdk] Memory leaks when inlcuding the libary in MFC project (#99) you can try it like this:open "Projects->properties->Linker->input" in "Additional Dependencies" add mfc120ud.lib mfcm120ud.lib

vs2017: mfc140ud.lib mfcm140ud.lib

At 2020-05-06 12:24:18, "Jack" notifications@github.com wrote:

I have the same problem. How can fix this issue

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

Currywurst commented 4 years ago

Hi, we have an large Multibyte MFC Project and we also get the FALSE Positive leaks. We can not simply add the MFC Unicode libs. I tryed to compile the cppRestSDK manually and link it as static, but then we have too many other issues ( with libz and more ).

Did anyone have an solution or an idea? What can we do to solve this problem?

Curry-Messi commented 4 years ago

嗨,我们有一个大型的多字节MFC项目,并且我们还得到了FALSE Positive泄漏。 我们不能简单地添加MFC Unicode库。 我尝试手动编译cppRestSDK并将其链接为静态链接,但是随后我们遇到了太多其他问题(libz等问题)。

有没有人有解决方案或想法?我们该怎么做才能解决这个问题? 微信图片_20200611092426

My vs2017 MFC LIBS path is "Microsoft Visual Studio 14.0 \ VC \ atlmfc \ lib". mfcxxx.lib before MFCMxxx.lib , this is very important

Aero9999 commented 1 year ago

I think this is because the statics in cpprest are cleared up after MFC calls _CrtDumpMemoryLeaks(), its a false positive.

The solution described here worked for me: https://groups.google.com/g/microsoft.public.vc.mfc/c/c0k93sFlpcs#e651b944da9c619d

I had to compile my own version of cpprest though with that new class.