Memory problems

May 16, 2014 at 7:42 PM
Edited May 16, 2014 at 7:49 PM
Hi ,

I got some memory problems when using the API.

The story is : when I use the API in a project, it crashes, and points to an memory-related error when I called:

http_client client(link);

where link is an instance of uri .

so I wrote a very simple program, and run it with Dr. memory:

void test(){
uri url(L"some link starting with http");
http_client client(url);
}
int main()
{
test();
}

I got the following reports.

Error #1: INVALID HEAP ARGUMENT: allocated with operator new, freed with free
     replace_free   
         d:\drmemory_package\common\alloc_replace.c(2380):
     MSVCP120D.dll!std::_DebugHeapDelete<>
         f:\dd\vctools\crt\crtw32\stdhpp\xdebug(62):
     MSVCP120D.dll!std::basic_streambuf<>::~basic_streambuf<>
         f:\dd\vctools\crt\crtw32\stdhpp\streambuf(80):
     cpprest120d_2_0.dll!std::basic_stringbuf<>::~basic_stringbuf<>
         ??:0
     cpprest120d_2_0.dll!std::basic_ostringstream<>::~basic_ostringstream<>
         ??:0
     cpprest120d_2_0.dll!std::basic_ostringstream<>::`vbase destructor'
         ??:0
     cpprest120d_2_0.dll!web::details::_uri_components::join
         ??:0
     cpprest120d_2_0.dll!web::uri::uri      
         ??:0
     test    
         c:\users\haow\documents\visual studio 2013\projects\rest\rest\rest.cpp(152):
     main    
         c:\users\haow\documents\visual studio 2013\projects\rest\rest\rest.cpp(158):
     Note: memory was allocated here:
                replace_operator_new
                    d:\drmemory_package\common\alloc_replace.c(2449):
                MSVCP120D.dll!std::basic_streambuf<>::basic_streambuf<>
                    f:\dd\vctools\crt\crtw32\stdhpp\streambuf(26):
                cpprest120d_2_0.dll!std::basic_stringbuf<>::basic_stringbuf<>
         ??:0
                cpprest120d_2_0.dll!std::basic_ostringstream<>::basic_ostringstream<>
         ??:0
                cpprest120d_2_0.dll!web::details::_uri_components::join
         ??:0
                cpprest120d_2_0.dll!web::uri::uri      
         ??:0
                test    
                    c:\users\haow\documents\visual studio 2013\projects\rest\rest\rest.cpp(152):
                main    
                    c:\users\haow\documents\visual studio 2013\projects\rest\rest\rest.cpp(158):

     Error #2: INVALID HEAP ARGUMENT: allocated with operator new, freed with free
     replace_free   
         d:\drmemory_package\common\alloc_replace.c(2380):
     MSVCP120D.dll!std::_DebugHeapDelete<>
         f:\dd\vctools\crt\crtw32\stdhpp\xdebug(62):
     MSVCP120D.dll!std::basic_streambuf<>::~basic_streambuf<>
         f:\dd\vctools\crt\crtw32\stdhpp\streambuf(80):
     cpprest120d_2_0.dll!std::basic_stringbuf<>::~basic_stringbuf<>
         ??:0
     cpprest120d_2_0.dll!std::basic_ostringstream<>::~basic_ostringstream<>
         ??:0
     cpprest120d_2_0.dll!std::basic_ostringstream<>::`vbase destructor'
         ??:0
     cpprest120d_2_0.dll!web::details::_uri_components::join
         ??:0
     cpprest120d_2_0.dll!web::uri::uri      
         ??:0
     cpprest120d_2_0.dll!web::http::client::web_proxy::web_proxy
         ??:0
     cpprest120d_2_0.dll!web::http::client::http_client_config::http_client_config
         ??:0
     cpprest120d_2_0.dll!web::http::client::http_client::http_client
         ??:0
     test    
         c:\users\haow\documents\visual studio 2013\projects\rest\rest\rest.cpp(153):
     Note: memory was allocated here:
                replace_operator_new
                    d:\drmemory_package\common\alloc_replace.c(2449):
                MSVCP120D.dll!std::basic_streambuf<>::basic_streambuf<>
                    f:\dd\vctools\crt\crtw32\stdhpp\streambuf(26):
                cpprest120d_2_0.dll!std::basic_stringbuf<>::basic_stringbuf<>
         ??:0
                cpprest120d_2_0.dll!std::basic_ostringstream<>::basic_ostringstream<>
         ??:0
                cpprest120d_2_0.dll!web::details::_uri_components::join
         ??:0
                cpprest120d_2_0.dll!web::uri::uri      
         ??:0
                cpprest120d_2_0.dll!web::http::client::web_proxy::web_proxy
         ??:0
                cpprest120d_2_0.dll!web::http::client::http_client_config::http_client_config
         ??:0
                cpprest120d_2_0.dll!web::http::client::http_client::http_client
         ??:0
                test    
                    c:\users\haow\documents\visual studio 2013\projects\rest\rest\rest.cpp(153):
                main    
                    c:\users\haow\documents\visual studio 2013\projects\rest\rest\rest.cpp(158):

     ERRORS FOUND:
           0 unique,     0 total unaddressable access(es)
           0 unique,     0 total uninitialized access(es)
           2 unique,     2 total invalid heap argument(s)
           0 unique,     0 total GDI usage error(s)
           0 unique,     0 total handle leak(s)
           0 unique,     0 total warning(s)
           0 unique,     0 total,      0 byte(s) of leak(s)
           0 unique,     0 total,      0 byte(s) of possible leak(s)

Is this normal? If this is fine, I will try to find some other errors.

BTW, I am using VS 2013, and got the SDK from NuGet.

Thank you very much !!!

Hao
May 20, 2014 at 2:36 AM
Hi Hao,

What you have looks like a trivial program. We have many customers using Casablanca doing a whole lot more quite successfully :). I'd really be surprised if there was in a bug in the library with this. I've never used Dr. Memory, but from what you describe I'm thinking there is some binary debug/release configuration mismatch issue.

You mention you 'got the SDK from NuGet', are you pulling the binary files out and manually setting up the libs and dlls? Following the exact steps in our http_client tutorial are you successful?

Thanks,
Steve