• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
C++ std::string tries to free() a not allocated pointer ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C++ std::string tries to free() a not allocated pointer ?


  • Subject: C++ std::string tries to free() a not allocated pointer ?
  • From: Jean-Denis Muys <email@hidden>
  • Date: Wed, 18 Nov 2009 19:06:24 +0100

Hi,

I solved my GDB not finding source code files. Here is the actual problem at hand, for which I am (perhaps not totally) stuck.

I have a weird problem in C++ code behavior, where a std::string uses the stack (I think) for its internal storage and yet calls free in its destructor. Of course, malloc complains:

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

Has anybody seen something similar?

Here are the details:

1- This happens when the string length is zero. Then of course, it doesn't really need any internal storage.

2- The std::string is the sole member of the class SQLstring, for which it is a wrapper:

class SQLString
{
	std::string realStr;
public:
	~SQLString() {}
	SQLString(const char * s, size_t n) : realStr(s, n) {}
};

[other public member functions irrelevant because not called.]

3- a buffer is allocated with 23 bytes in the library, form which a SQLString is constructed.
The calling sequence I stepped through in the library is:

buffer = new char[23];
buffer[0] = 0;
length = 0;
return SQLString(buffer, length);

4- that return statement constructs a temporary SQLString through that call chain:

#0  0x99056cb4 in std::string::_S_construct<char const*> ()
#1  0x99056d85 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string ()
#2  0x041fc8c7 in sql::SQLString::SQLString (this=0xb02e6a4c, s=0x4beccb0 "", n=0) at sqlstring.h:43

I have a hard time stepping through here, because I couldn't find the source code for std::string::_S_construct<char const*> (). The best I found is in string-inst.cc:

template
  C*
  S::_S_construct(const C*, const C*, const allocator<C>&,
		    forward_iterator_tag);

It's declared, but no source code.

5- trying to reduce the problem through a toy program running the same call sequence failed: the toy program doesn't misbehave.

At this point, I call for help, in case somebody has ever encountered something similar. Please note that this is 100% reproducible on my machine. My code is a 4D plugin that calls to mySQL through their connector-C++ driver. So it's not very easy to replicate my working environment (though not impossible).

Thanks a million.

Jean-Denis
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: C++ std::string tries to free() a not allocated pointer ?
      • From: Howard Moon <email@hidden>
    • Re: C++ std::string tries to free() a not allocated pointer ?
      • From: Robert Schwalbe <email@hidden>
    • Re: C++ std::string tries to free() a not allocated pointer ?
      • From: David Hayes <email@hidden>
    • Re: C++ std::string tries to free() a not allocated pointer ?
      • From: Scott Ribe <email@hidden>
  • Prev by Date: Re: Xcode 3.1 SCM breaks after installing Subversion 1.6
  • Next by Date: Re: Xcode 3.1 SCM breaks after installing Subversion 1.6
  • Previous by thread: RE: Seapine SCM and Xcode
  • Next by thread: Re: C++ std::string tries to free() a not allocated pointer ?
  • Index(es):
    • Date
    • Thread