By dan


2010-02-10 05:11:59 8 Comments

I'm trying to use std:getline() but getting a strange runtime error:

malloc: * error for object 0x10000a720: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug

This is the code that produces this error:

//main.cpp
#include <iostream>
#include <sstream>

int main (int argc, char * const argv[])
{
   std::istringstream my_str("demo string with spaces");
   std::string word;

   while (std::getline(my_str, word, ' ')) {
        std::cout << word << std::endl;
   }
   return 0;
}

Before each word I get this error. From the comments it seems to be a OSX/XCode specific error. Any hints on that?

Update: The error is only printed in Debug mode. If I build this code in Release mode everything is fine.

Update 2: More info on that issue can be found here.

Solution:

Set

_GLIBCXX_FULLY_DYNAMIC_STRING=1

in your Preprocessor Macros in targets info build tab.

System info:

OSX 10.6.2 | XCode 3.2 | g++ 4.2 | debug config for i386

1 comments

@Michael Burr 2010-02-10 06:47:39

At least one person has reported problems with g++ 4.2.1 on Apple that seem possibly related to yours having to do with an improper configuration of the standard library with the _GLIBCXX_FULLY_DYNAMIC_STRING definition (not that I understand any of what I'm typing here).

You might get a bit of a clue from the newsgroup thread that includes this message:

@Potatoswatter 2010-02-10 07:27:02

This is it. I reproduced the problem and fixed it by adding _GLIBCXX_FULLY_DYNAMIC_STRING to the target settings window. (Do not add it to the "Preprocessing" section of the Project settings window; that does nothing. XCode, grrrrr…)

@Potatoswatter 2010-02-10 07:29:39

Since this is a team effort, would someone like to report a bug?

Related Questions

Sponsored Content

37 Answered Questions

9 Answered Questions

[SOLVED] Pretty-print C++ STL containers

2 Answered Questions

[SOLVED] gdb on macOs Mojave 10.14.2

  • 2019-01-29 08:47:12
  • zhihuifan
  • 1374 View
  • 2 Score
  • 2 Answer
  • Tags:   macos gdb

1 Answered Questions

[SOLVED] c++ error C2039 only on release

  • 2018-01-16 15:46:11
  • ziraak
  • 160 View
  • 0 Score
  • 1 Answer
  • Tags:   c++ visual-studio

1 Answered Questions

[SOLVED] Eclipse Kepler: #include "boost/filesystem.hpp" breaking debugging?

0 Answered Questions

malloc error when computing descriptor OpenCV

1 Answered Questions

Decrease retain count While ARC mode is Enabled

1 Answered Questions

[SOLVED] Template class error in xcode

1 Answered Questions

iphone c++ xcode 4.0 ios 4.3

Sponsored Content