Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-63274

QString::toStdString() doesn't call new operator but delete operator is called on destruction with invalid pointer

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.8.0
    • Core: Other
    • None
    • Windows 7, Visual Studio 2015, x64, using MSVC multi-threaded runtime DLLs, Qt 5.8 

    Description

      I have a large application that implements global overloaded new/delete operators.  When I debug and place breakpoints at the overloaded new and delete operators and try this code (with QString qsFilter)

      const std::string fs = qsFilter.toStdString(); 
      

      OR this code

            const QByteArray ba( qsFilter.toLocal8Bit() );
      
            const std::string fs = ba.toStdString();
      

      it doesn't hit the breakpoint at my overloaded new operator, however when the object comes out of scope and is destroyed, it hits the breakpoint at my overloaded delete operator with a bad pointer and the application crashes when it attempts to free memory using this invalid pointer.

      On the other hand, this code behaves as expected and it hits both breakpoints:

       

         {
            const QByteArray ba( qsFilter.toLocal8Bit() );     
             const std::string fs = ba.constData(); 
         }
      

       

      NOTE: I used Dependency Walker to make sure that I wasn't linking to new/delete operators in some other library, so I know that this is not the issue.  This only seems to happen with toStdString() and also with toStdWString().  The application program runs fine without any other issues that I would expect if this was the case.

      I ended up going through the code in the application program and replacing (for now) code that was calling toStdString() with qPrintable(..) or the equivalent QByteArray based code that I know works well.

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            rtauber Richard Tauber
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes