• 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
Re: C++ std::string tries to free() a not allocated pointer ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Re: C++ std::string tries to free() a not allocated pointer ?
  • From: Howard Moon <email@hidden>
  • Date: Thu, 19 Nov 2009 08:09:39 -0800


On Nov 18, 2009, at 10:06 AM, Jean-Denis Muys wrote:

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




sql::SQLString temp = res->getString(colNum); // getString basically does "return sql::SQLString(p, 0);" where p points to a new char[23]


I don't know if it will help you track down the problem or not, but I don't think there is any temporary SQLString being created here. If I recall, any modern compiler will almost certainly construct the object in place, not create a temporary. So stack-trace line #2 should be creating the variable "temp" itself, not a temporary. This avoids the overhead of calling an assignment operator and destroying the temporary. But like I said, I don't know if that will help you track down the problem.

However, the fact that your "toy" program doesn't misbehave makes me suspect that you've got a bug elsewhere in the code that is only being *exhibited* when this code is run. That's a common problem, and can often be caused by using uninitialized pointer variables, by buffer overruns, or by deleting an object twice.

-Howard


_______________________________________________ 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
References: 
 >C++ std::string tries to free() a not allocated pointer ? (From: Jean-Denis Muys <email@hidden>)

  • Prev by Date: Re: C++ std::string tries to free() a not allocated pointer ?
  • Next by Date: Re: Haywired Call Stack in resymbolized Crash Report
  • Previous by thread: Re: C++ std::string tries to free() a not allocated pointer ?
  • Next by thread: Re: C++ std::string tries to free() a not allocated pointer ?
  • Index(es):
    • Date
    • Thread