Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8011579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:03:30+00:00 2026-06-04T19:03:30+00:00

Well, here again, this time the compiler is showing me a memory error (leak):

  • 0

Well, here again, this time the compiler is showing me a memory error (leak):

otest(18015,0xacae32c0) malloc: * error for object 0x194e734:
incorrect checksum for freed object – object was probably modified
after being freed.
*
set a breakpoint in malloc_error_break to debug

I’m using clang with ARC activated and STL, this is a C++ file (.cpp).

What I found: If I comment the “delete” line it runs without problems. It makes me wonder who is freeing my allocated memory (cStr).

Btw. This code takes a query string (arg=abc&arg2=asdb) and returns a map whit those values.

static map<string, string> getDecodedQueryString( string qs ) {
            map<string, string> r;

            qs = qs+"&";

            char key[100], value[100],  * cStr, *ptr;
            cStr = new char[ qs.length() ];
            memcpy( cStr, qs.c_str(), url.length()-1);
            cStr[qs.length()]=0;

            ptr =  strtok(cStr, "&");
            while ( ptr != NULL && sscanf( ptr, "%[^=]=%[^&]", &key, &value ) == 2) { 
                r[key]=value;
                ptr = strtok(NULL, "&");
            }
            delete [] cStr; //leaking?

            return r; 
        }

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:03:33+00:00Added an answer on June 4, 2026 at 7:03 pm

    The problem is likely in these lines:

        cStr = new char[ qs.length() ];
        memcpy( cStr, qs.c_str(), url.length()-1);
        cStr[qs.length()]=0;
    

    Even without the memcpy() (which may have its own problems due to the length of url, as I mentioned above in a comment), the cStr[qs.length()] = 0 writes one byte past the end of the buffer.

    If your compiler has strdup() available (it’s nonstandard, but most do), you can replace this with:

    cStr = strdup(qs.c_str());
    // ...
    free(cStr);
    

    This saves you from having to mess around with manually allocating bytes, copying them, null terminating in the right place, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Well,this is the first time i ask questions here and English isn't my first
this is my first time asking a question here. I tried to be well
Well i need some help here i don't know how to solve this problem.
Hmm well there's lots here about this but I can't seem to get a
Well, I tried and failed so, here I am again. I need to match
EDIT : Let's try this again. This time I've used the AdventureWorks sample database
Extreme Android developer newbie here...well, new to Android development, not development in general. I
Well i am here writing some constraints for a db I am working on
Well, here's what I have to do. I need to trim the whitespaces in
Here is my code (well, some of it). The question I have is, can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.