Sign in to follow this  
chrisparton1991

C++: Strange malloc error with std::string

Recommended Posts

Hey, for some reason I can't seem to perform the simplest of input operations into a string using Xcode whilst in debug mode (On OSX 10.6). For example:
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string someWord;
	cin >> someWord;
	if (someWord == "exit")
	{
		cout << "exit has been entered." << endl;
	}
	return 0;
}




If I do a debug build of the above code, it returns the following error after input (regardless of what's being typed): Using Strings(2838) malloc: *** error for object 0x1000041e0: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug Abort trap Does anyone know why this would happen? Cheers. [Edited by - jpetrie on November 11, 2009 9:55:44 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by chrisparton1991


Using Strings(2838) malloc: *** error for object 0x1000041e0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap


Does anyone know why this would happen? Cheers.


This is a bug in the 10.6 SDK.

Share this post


Link to post
Share on other sites
Weird... That's a pretty big bug then. Do you think it's safe to just do release builds or will It just mask the error? The code runs fine when run as a release build.

Thanks, I was wondering why something as simple as that wasn't working.

EDIT: I looked it up and found that removing the preprocessor macros _GLIBCXX_DEBUG=1 and _GLIBCXX_DEBUG_PEDANTIC=1 fixes the debug error.

[Edited by - chrisparton1991 on November 11, 2009 9:20:43 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this